本文整理匯總了Python中web.database方法的典型用法代碼示例。如果您正苦於以下問題:Python web.database方法的具體用法?Python web.database怎麽用?Python web.database使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類web
的用法示例。
在下文中一共展示了web.database方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_dbn
# 需要導入模塊: import web [as 別名]
# 或者: from web import database [as 別名]
def get_dbn(cfg_file = "config.cfg"):
parser = ConfigParser.SafeConfigParser()
parser.optionxform = str
cn_db_file = os.getenv("CN_DB")
if cn_db_file is not None:
#print "*** USING DATABASE", cn_db_file
cfg_file = cn_db_file
if os.path.exists(cfg_file):
parser.read(cfg_file)
else:
tmp = os.path.dirname(os.path.realpath(__file__))
parser.read(os.path.join(tmp, cfg_file))
section = 'database'
if 'database' not in parser.sections():
raise Exception("No database section in " + cfg_file)
return parser.get(section, 'dbn')
#-----------------------------------------------------------------------
示例2: get_dbn
# 需要導入模塊: import web [as 別名]
# 或者: from web import database [as 別名]
def get_dbn():
parser = ConfigParser.SafeConfigParser()
parser.optionxform = str
parser.read("config.cfg")
section = 'database'
if 'database' not in parser.sections():
raise Exception("No database section in config.cfg")
return parser.get(section, 'dbn')
#-----------------------------------------------------------------------
示例3: init_web_db
# 需要導入模塊: import web [as 別名]
# 或者: from web import database [as 別名]
def init_web_db():
parser = ConfigParser.SafeConfigParser()
parser.optionxform = str
parser.read("config.cfg")
section = 'database'
if 'database' not in parser.sections():
raise Exception("No database section in config.cfg")
dbn = parser.get(section, 'dbn')
if dbn == "mysql":
db = parser.get(section, 'db')
user = parser.get(section, 'user')
pw = parser.get(section, 'pw')
host = parser.get(section, 'host')
db = web.database(dbn='mysql', db=db, user=user, pw=pw, host=host)
db.query('SET NAMES utf8;')
db.query('SET CHARACTER SET utf8;')
db.query('SET character_set_connection=utf8;')
elif dbn == "sqlite":
dbname = parser.get(section, 'db')
db = web.database(dbn='sqlite', db=dbname)
# We need to mimic some MySQL functions in order to be able to use
# SQLite or use different SQL commands for each database server. I
# prefer the 1st option, naturally...
db._db_cursor().connection.create_function("concat", 2, sqlite_concat)
db._db_cursor().connection.create_function("conv", 3, sqlite_conv)
db._db_cursor().connection.create_function("instr", 2, sqlite_instr)
db._db_cursor().connection.create_function("rand", 0, sqlite_rand)
return db
#-----------------------------------------------------------------------
示例4: get_dbn
# 需要導入模塊: import web [as 別名]
# 或者: from web import database [as 別名]
def get_dbn(cfg_file="config.cfg"):
parser = ConfigParser.SafeConfigParser()
parser.optionxform = str
parser.read(cfg_file)
section = 'database'
if 'database' not in parser.sections():
raise Exception("No database section in %s" % cfg_file)
return parser.get(section, 'dbn')
#-------------------------------------------------------------------------------
示例5: init_web_db
# 需要導入模塊: import web [as 別名]
# 或者: from web import database [as 別名]
def init_web_db(cfg_file="config.cfg"):
parser = ConfigParser.SafeConfigParser()
parser.optionxform = str
parser.read(cfg_file)
section = 'database'
if 'database' not in parser.sections():
raise Exception("No database section in %s" % cfg_file)
dbn = parser.get(section, 'dbn')
if dbn == "mysql":
db = parser.get(section, 'db')
user = parser.get(section, 'user')
pw = parser.get(section, 'pw')
host = parser.get(section, 'host')
db = web.database(dbn='mysql', db=db, user=user, pw=pw, host=host)
db.query('SET NAMES utf8;')
db.query('SET CHARACTER SET utf8;')
db.query('SET character_set_connection=utf8;')
elif dbn == "sqlite":
dbname = parser.get(section, 'db')
db = web.database(dbn='sqlite', db=dbname)
# We need to mimic some MySQL functions in order to be able to use
# SQLite or use different SQL commands for each database server. I
# prefer the 1st option, naturally...
db._db_cursor().connection.create_function("concat", 2, sqlite_concat)
db._db_cursor().connection.create_function("conv", 3, sqlite_conv)
db._db_cursor().connection.create_function("instr", 2, sqlite_instr)
db._db_cursor().connection.create_function("rand", 0, sqlite_rand)
db._db_cursor().connection.text_factory = str
return db
#-------------------------------------------------------------------------------
示例6: GET
# 需要導入模塊: import web [as 別名]
# 或者: from web import database [as 別名]
def GET(self):
try:
if 'user' in session:
domains = db.query('SELECT * FROM DDNS WHERE user_id=$user_id',
vars={'user_id': session.user['ID']})
return render.ddns(domains, DDNSIndex.ddns_add_form())
else:
web.seeother('/login')
except Exception as e:
flash('error', 'Please update the database schema. See README for details.')
web.debug(traceback.print_exc())
raise web.seeother('/')
示例7: GET
# 需要導入模塊: import web [as 別名]
# 或者: from web import database [as 別名]
def GET(self):
pmd = self.get_phpmyadmin_dir();
web.ctx.session.phpmyadminDir = False
if pmd:
web.ctx.session.phpmyadminDir = 'http://' + web.ctx.host.split(':')[0] + ':'+ pmd[1] + '/' + pmd[0];
data = {}
data['isSetup'] = True;
data['mysql_root'] = public.M('config').where('id=?',(1,)).getField('mysql_root');
data['lan'] = public.getLan('database')
if os.path.exists(web.ctx.session.setupPath+'/mysql') == False: data['isSetup'] = False;
return render.database(data)
示例8: POST
# 需要導入模塊: import web [as 別名]
# 或者: from web import database [as 別名]
def POST(self):
import database
databaseObject = database.database()
defs = ('GetSlowLogs','GetRunStatus','SetDbConf','GetDbStatus','BinLog','GetErrorLog','GetMySQLInfo','SetDataDir','SetMySQLPort','AddDatabase','DeleteDatabase','SetupPassword','ResDatabasePassword','ToBackup','DelBackup','InputSql','SyncToDatabases','SyncGetDatabases','GetDatabaseAccess','SetDatabaseAccess')
return publicObject(databaseObject,defs);
示例9: init_web_db
# 需要導入模塊: import web [as 別名]
# 或者: from web import database [as 別名]
def init_web_db(cfg_file = "config.cfg"):
parser = ConfigParser.SafeConfigParser()
parser.optionxform = str
cn_db_file = os.getenv("CN_DB")
if cn_db_file is not None:
#print "*** USING DATABASE", cn_db_file
cfg_file = cn_db_file
if os.path.exists(cfg_file):
parser.read(cfg_file)
else:
tmp = os.path.dirname(os.path.realpath(__file__))
parser.read(os.path.join(tmp, cfg_file))
section = 'database'
if 'database' not in parser.sections():
raise Exception("No database section in " + cfg_file)
dbn = parser.get(section, 'dbn')
if dbn == "mysql":
db = parser.get(section, 'db')
user = parser.get(section, 'user')
pw = parser.get(section, 'pw')
host = parser.get(section, 'host')
db = web.database(dbn='mysql', db=db, user=user, pw=pw, host=host)
db.query('SET NAMES utf8;')
db.query('SET CHARACTER SET utf8;')
db.query('SET character_set_connection=utf8;')
elif dbn == "sqlite":
dbname = parser.get(section, 'db')
db = web.database(dbn='sqlite', db=dbname)
# We need to mimic some MySQL functions in order to be able to use
# SQLite or use different SQL commands for each database server. I
# prefer the 1st option, naturally...
db._db_cursor().connection.create_function("concat", 2, sqlite_concat)
db._db_cursor().connection.create_function("conv", 3, sqlite_conv)
db._db_cursor().connection.create_function("instr", 2, sqlite_instr)
db._db_cursor().connection.create_function("rand", 0, sqlite_rand)
return db
#-----------------------------------------------------------------------