當前位置: 首頁>>代碼示例>>Python>>正文


Python web.database方法代碼示例

本文整理匯總了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')

#----------------------------------------------------------------------- 
開發者ID:joxeankoret,項目名稱:cosa-nostra,代碼行數:23,代碼來源:cn_db.py

示例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')

#----------------------------------------------------------------------- 
開發者ID:joxeankoret,項目名稱:nightmare,代碼行數:14,代碼來源:nfp_db.py

示例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

#----------------------------------------------------------------------- 
開發者ID:joxeankoret,項目名稱:nightmare,代碼行數:38,代碼來源:nfp_db.py

示例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')

#------------------------------------------------------------------------------- 
開發者ID:joxeankoret,項目名稱:maltindex,代碼行數:14,代碼來源:web_db.py

示例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

#------------------------------------------------------------------------------- 
開發者ID:joxeankoret,項目名稱:maltindex,代碼行數:40,代碼來源:web_db.py

示例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('/') 
開發者ID:ab77,項目名稱:netflix-proxy,代碼行數:14,代碼來源:auth.py

示例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) 
開發者ID:NNBBXX,項目名稱:BaoTa-Panel,代碼行數:14,代碼來源:main.py

示例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); 
開發者ID:NNBBXX,項目名稱:BaoTa-Panel,代碼行數:7,代碼來源:main.py

示例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

#----------------------------------------------------------------------- 
開發者ID:joxeankoret,項目名稱:cosa-nostra,代碼行數:47,代碼來源:cn_db.py


注:本文中的web.database方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。