本文整理汇总了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
#-----------------------------------------------------------------------