Python web.database() Examples
The following are 9
code examples of web.database().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
web
, or try the search function
.
Example #1
Source File: cn_db.py From cosa-nostra with GNU General Public License v3.0 | 6 votes |
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') #-----------------------------------------------------------------------
Example #2
Source File: nfp_db.py From nightmare with GNU General Public License v2.0 | 5 votes |
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') #-----------------------------------------------------------------------
Example #3
Source File: nfp_db.py From nightmare with GNU General Public License v2.0 | 5 votes |
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 #-----------------------------------------------------------------------
Example #4
Source File: web_db.py From maltindex with GNU General Public License v2.0 | 5 votes |
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') #-------------------------------------------------------------------------------
Example #5
Source File: web_db.py From maltindex with GNU General Public License v2.0 | 5 votes |
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 #-------------------------------------------------------------------------------
Example #6
Source File: auth.py From netflix-proxy with MIT License | 5 votes |
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('/')
Example #7
Source File: main.py From BaoTa-Panel with GNU General Public License v3.0 | 5 votes |
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)
Example #8
Source File: main.py From BaoTa-Panel with GNU General Public License v3.0 | 5 votes |
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);
Example #9
Source File: cn_db.py From cosa-nostra with GNU General Public License v3.0 | 4 votes |
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 #-----------------------------------------------------------------------