def __init__(self, host, db, port='3050', user='******', password='******', autoCommit=1, dialect=None, role=None, charset=None, **kw): global kinterbasdb if kinterbasdb is None: import kinterbasdb # See http://kinterbasdb.sourceforge.net/dist_docs/usage.html # for an explanation; in short: use datetime, decimal and unicode. kinterbasdb.init(type_conv=200) self.module = kinterbasdb self.host = host self.port = port self.db = db self.user = user self.password = password if dialect: self.dialect = int(dialect) else: self.dialect = None self.role = role if charset: self.dbEncoding = charset.replace('-', '') # encoding defined by user in the connection string else: self.dbEncoding = charset self.defaultDbEncoding = '' # encoding defined during database creation and stored in the database DBAPI.__init__(self, **kw)
def __init__(self, *args, **kwargs): super(DatabaseWrapper, self).__init__(*args, **kwargs) settings_dict = self.settings_dict self.settings = { 'charset': 'UNICODE_FSS', 'dialect': 3, } if settings_dict['HOST']: self.settings['host'] = settings_dict['HOST'] if settings_dict['NAME']: self.settings['database'] = settings_dict['NAME'] if settings_dict['USER']: self.settings['user'] = settings_dict['USER'] if settings_dict['PASSWORD']: self.settings['password'] = settings_dict['PASSWORD'] self.settings.update(settings_dict['OPTIONS']) self.dialect = self.settings['dialect'] if 'init_params' in self.settings: Database.init(**self.settings['init_params']) self.server_version = None self.features = DatabaseFeatures(self) self.ops = DatabaseOperations(self, dialect=self.dialect) self.client = DatabaseClient(self) self.creation = DatabaseCreation(self) self.introspection = DatabaseIntrospection(self) self.validation = BaseDatabaseValidation(self)
def connect(self): import kinterbasdb try: kinterbasdb.init(type_conv=0) except: pass self._db = kinterbasdb.connect(dsn=self._bdd, user=self._user, password=self._password, charset=self._charset) try: self._db.cursor().execute("DECLARE EXTERNAL FUNCTION lpad \ CSTRING(255) NULL, INTEGER, CSTRING(1) NULL \ RETURNS CSTRING(255) FREE_IT \ ENTRY_POINT 'IB_UDF_lpad' MODULE_NAME 'ib_udf'") except: pass try: self._db.cursor().execute("DECLARE EXTERNAL FUNCTION Round \ INT BY DESCRIPTOR, INT BY DESCRIPTOR \ RETURNS PARAMETER 2 \ ENTRY_POINT 'fbround' MODULE_NAME 'fbudf'") except: pass
def __init__(self, host, db, port='3050', user='******', password='******', autoCommit=1, dialect=None, role=None, charset=None, **kw): drivers = kw.pop('driver', None) or 'fdb,kinterbasdb' for driver in drivers.split(','): driver = driver.strip() if not driver: continue try: if driver == 'fdb': import fdb self.module = fdb elif driver == 'kinterbasdb': import kinterbasdb # See # http://kinterbasdb.sourceforge.net/dist_docs/usage.html # for an explanation; in short: use datetime, decimal and # unicode. kinterbasdb.init(type_conv=200) self.module = kinterbasdb elif driver in ('firebirdsql', 'pyfirebirdsql'): import firebirdsql self.module = firebirdsql else: raise ValueError( 'Unknown FireBird driver "%s", ' 'expected fdb, kinterbasdb or firebirdsql' % driver) except ImportError: pass else: break else: raise ImportError('Cannot find an FireBird driver, tried %s' % drivers) self.host = host self.port = port self.db = db self.user = user self.password = password if dialect: self.dialect = int(dialect) else: self.dialect = None self.role = role if charset: # Encoding defined by user in the connection string. self.dbEncoding = charset.replace('-', '') else: self.dbEncoding = charset # Encoding defined during database creation and stored in the database. self.defaultDbEncoding = '' DBAPI.__init__(self, **kw)
def connect(self): if self.rdbms == 'mssql': import socket #( To get the computer name for a SQL Server instance. import ipymssql #( Custom IronPython .NET Data Provider for SQL Server Instance = socket.gethostname() + r"\SILFW" Database = 'TestLangProj' conStr = 'Data Source=%s; Initial Catalog=%s; Integrated Security=True' % (Instance, Database) con = ipymssql.connect(conStr) elif self.rdbms == 'fb' or self.rdbms == 'firebird': import kinterbasdb #( http://kinterbasdb.sourceforge.net #( kinterbasdb must be initialized for life to be happy. See #( "Incompatibilities" at the top of: #( #( http://kinterbasdb.sourceforge.net/dist_docs/usage.html #( #( The default for kinterbasdb.init is only for backward compatibility. #( The reasons for this are written up at: #( #( http://kinterbasdb.sourceforge.net/dist_docs/usage.html#faq_fep_is_mxdatetime_required #( #( The ideal is to use type_conv=200 kinterbasdb.init(type_conv=200) con = kinterbasdb.connect( dsn = 'C:\Program Files\Firebird_2_0\Data\TESTLANGPROJ.FDB', user = "******", password = "******", charset = 'UTF8', dialect = 3) return con
def __init__(self, host, db, port='3050', user='******', password='******', autoCommit=1, dialect=None, role=None, charset=None, **kw): drivers = kw.pop('driver', None) or 'fdb,kinterbasdb' for driver in drivers.split(','): driver = driver.strip() if not driver: continue try: if driver == 'fdb': import fdb self.module = fdb elif driver == 'kinterbasdb': import kinterbasdb # See # http://kinterbasdb.sourceforge.net/dist_docs/usage.html # for an explanation; in short: use datetime, decimal and # unicode. kinterbasdb.init(type_conv=200) self.module = kinterbasdb elif driver in ('firebirdsql', 'pyfirebirdsql'): import firebirdsql self.module = firebirdsql else: raise ValueError( 'Unknown FireBird driver "%s", ' 'expected fdb, kinterbasdb or firebirdsql' % driver) except ImportError: pass else: break else: raise ImportError( 'Cannot find an FireBird driver, tried %s' % drivers) self.host = host self.port = port self.db = db self.user = user self.password = password if dialect: self.dialect = int(dialect) else: self.dialect = None self.role = role if charset: # Encoding defined by user in the connection string. self.dbEncoding = charset.replace('-', '') else: self.dbEncoding = charset # Encoding defined during database creation and stored in the database. self.defaultDbEncoding = '' DBAPI.__init__(self, **kw)
def __init__(self, module = None, **params): global _initialized_kb self.module = module or dbmodule self.opts = {} if not _initialized_kb: _initialized_kb = True type_conv = params.get('type_conv', 200) or 200 if isinstance(type_conv, types.StringTypes): type_conv = int(type_conv) concurrency_level = params.get('concurrency_level', 1) or 1 if isinstance(concurrency_level, types.StringTypes): concurrency_level = int(concurrency_level) if kinterbasdb is not None: kinterbasdb.init(type_conv=type_conv, concurrency_level=concurrency_level) ansisql.ANSIDialect.__init__(self, **params)
def __init__( self, host, db, port="3050", user="******", password="******", autoCommit=1, dialect=None, role=None, charset=None, **kw ): try: import fdb self.module = fdb except ImportError: import kinterbasdb # See http://kinterbasdb.sourceforge.net/dist_docs/usage.html # for an explanation; in short: use datetime, decimal and # unicode. kinterbasdb.init(type_conv=200) self.module = kinterbasdb self.host = host self.port = port self.db = db self.user = user self.password = password if dialect: self.dialect = int(dialect) else: self.dialect = None self.role = role if charset: # Encoding defined by user in the connection string. self.dbEncoding = charset.replace("-", "") else: self.dbEncoding = charset # Encoding defined during database creation and stored in the database. self.defaultDbEncoding = "" DBAPI.__init__(self, **kw)
def __init__(self): dBackend.__init__(self) self.dbModuleName = "kinterbasdb" self.fieldPat = re.compile("([A-Za-z_][A-Za-z0-9-_$]+)\.([A-Za-z_][A-Za-z0-9-_$]+)") self.paramPlaceholder = "?" import kinterbasdb initialized = getattr(kinterbasdb, "initialized", None) if not initialized: if initialized is None: # type_conv=200 KeyError with the older versions. User will need # mxDateTime installed as well: kinterbasdb.init() else: # Use Python's Decimal and datetime types: if kinterbasdb.__version__[0] == 3 and kinterbasdb.__version__[1] >= 3: # use type_conv=300 for blob encoding kinterbasdb.init(type_conv=300) dabo.dbActivityLog.info("kinterbasdb.init(type_conv=300)") else: kinterbasdb.init(type_conv=200) dabo.dbActivityLog.info("kinterbasdb.init(type_conv=200)") if initialized is None: # Older versions of kinterbasedb didn't have this attribute, so we write # it ourselves: kinterbasdb.initialized = True self.dbapi = kinterbasdb
def __init__(self): dBackend.__init__(self) self.dbModuleName = "kinterbasdb" self.fieldPat = re.compile( "([A-Za-z_][A-Za-z0-9-_$]+)\.([A-Za-z_][A-Za-z0-9-_$]+)") self.paramPlaceholder = "?" import kinterbasdb initialized = getattr(kinterbasdb, "initialized", None) if not initialized: if initialized is None: # type_conv=200 KeyError with the older versions. User will need # mxDateTime installed as well: kinterbasdb.init() else: # Use Python's Decimal and datetime types: if kinterbasdb.__version__[ 0] == 3 and kinterbasdb.__version__[1] >= 3: # use type_conv=300 for blob encoding kinterbasdb.init(type_conv=300) dabo.dbActivityLog.info("kinterbasdb.init(type_conv=300)") else: kinterbasdb.init(type_conv=200) dabo.dbActivityLog.info("kinterbasdb.init(type_conv=200)") if initialized is None: # Older versions of kinterbasedb didn't have this attribute, so we write # it ourselves: kinterbasdb.initialized = True self.dbapi = kinterbasdb
def __init__(self, host, db, port='3050', user='******', password='******', autoCommit=1, dialect=None, role=None, charset=None, **kw): try: import fdb self.module = fdb except ImportError: import kinterbasdb # See http://kinterbasdb.sourceforge.net/dist_docs/usage.html # for an explanation; in short: use datetime, decimal and # unicode. kinterbasdb.init(type_conv=200) self.module = kinterbasdb self.host = host self.port = port self.db = db self.user = user self.password = password if dialect: self.dialect = int(dialect) else: self.dialect = None self.role = role if charset: # Encoding defined by user in the connection string. self.dbEncoding = charset.replace('-', '') else: self.dbEncoding = charset # Encoding defined during database creation and stored in the database. self.defaultDbEncoding = '' DBAPI.__init__(self, **kw)
import kinterbasdb import time from random import random import logging kinterbasdb.init(type_conv=0) TIME_FORMAT = "%Y-%m-%d %H:%M:%S" def main(): db = FirebirdDB("localhost:/var/lib/firebird/2.0/data/test.fdb") now = time.time() for i in range (0, 10000): writeDB(db, time.localtime(now+(600*i))) print i def writeDB(db, t): sql = """ INSERT INTO METEO (TIMESTAMP_UTC, TIMESTAMP_LOCAL, TEMP, TEMP_MIN, TEMP_MIN_TIME, TEMP_MAX, TEMP_MAX_TIME, HUM, WIND, WIND_DIR, WIND_GUST, WIND_GUST_DIR, WIND_GUST_TIME, DEW_POINT, RAIN, RAIN_RATE, RAIN_RATE_TIME, PRESSURE, UV_INDEX) VALUES (%s, %s, %g, %g, %s, %g, %s, %g, %g, %s, %g, %s, %s, %g, %g, %g, %s, %g, %s) """ % ("'%s'" % time.strftime(TIME_FORMAT, t), "'%s'" % time.strftime(TIME_FORMAT, t), random()*20-5, random()*10-10, "'%s'" % time.strftime(TIME_FORMAT, t), random()*30+10, "'%s'" % time.strftime(TIME_FORMAT, t), random()*100, random()*10,
""" Export cqm firebird data to dbf for BIOS system Autor: Ruslan Keba <*****@*****.**> Date: 2007-10-16 Site: www.infitis.dp.ua """ import sys from dbfpy.dbf import * from dbfpy.dbfnew import * import kinterbasdb as fb fb.init(type_conv=200) from shutil import copyfile #FB_HOST = "172.17.24.23" FB_HOST = "localhost" FB_USER = "******" FB_PASS = "******" FB_DB = "stash" DBF_FILE = "otk.dbf" def main(): # get date print "\n\ +------------------------------------------+\n\ | |\n\ | MKU -> BIOS |\n\ | |\n\
## along with this program. If not, see <http://www.gnu.org/licenses/>. import datetime import decimal try: import kinterbasdb if __name__ == "__main__": print "firebird driver present" except ImportError: kinterbasdb = None if kinterbasdb: try: kinterbasdb.init(type_conv=199) # Set type conversion (datetime / floats) if __name__ == "__main__": print "firebird conversion 199" # kinterbasdb.init(type_conv=200) # Set type conversion (datetime / decimal) except: try: kinterbasdb.init(type_conv=0) # Set type conversion (time tuple / floats) old python 2.5 if __name__ == "__main__": print "firebird conversion 0" except: pass try: import MySQLdb if __name__ == "__main__": print "mysql driver present"
#!/usr/local/bin/python # -*- coding: utf-8 -*- '''test_fb ''' import sys, os import datetime import kinterbasdb DBNAME = 'c:/Firebird/testdb1.fdb' DBUSER = '******' DBPASS = '******' DBCHAR = 'UTF8' if not kinterbasdb.initialized: kinterbasdb.init(type_conv=200, concurrency_level=1) def test_fb(): cn = kinterbasdb.connect(dsn=DBNAME, user=DBUSER, password=DBPASS, charset=DBCHAR) cur = cn.cursor() cur.execute('''insert into ttest (id, c1, c2) values (3, 'xyz', 'abc');''') cur.execute('''insert into ttest (id, c1, c2) values (3, 'abc', 'xyz');''') cur.execute('''insert into ttest (id, c1, c2) values (3, 'bbb', 'aaa');''') cn.commit() cur.execute('''select * from ttest;''') for row in cur.fetchall(): print row
import sys, os import md5 import subprocess import datetime import kinterbasdb BUFSIZ = 40#96 DBPATH = 'privatedata' DBNAME = os.path.join(os.path.dirname(__file__), DBPATH, 'fbssccpp.fdb') DBUSER = '******' # from config DBPASS = '******' # from config DBCHAR = 'UTF8' if not kinterbasdb.initialized: kinterbasdb.init(type_conv=200, concurrency_level=1) """ cn = kinterbasdb.create_database(''' create database '%s' page_size 16384 user '%s' password '%s' default character set %s; ''' % ( DBNAME, DBUSER, DBPASS, DBCHAR)) cn.close() # create table / unique index / sequence / trigger ... """ class SSCCPP(object): def __init__(self, argv): self.argv = argv self.basedir = os.path.join(os.path.dirname(__file__), 'data')
import re import sys import kinterbasdb as FB import krconst FB.default_tpb = ( # isc_tpb_version3 is a *purely* infrastructural value. kinterbasdb will # gracefully handle user-specified TPBs that don't start with # isc_tpb_version3 (as well as those that do start with it). FB.isc_tpb_version3 + FB.isc_tpb_write # Access mode + FB.isc_tpb_read_committed + FB.isc_tpb_rec_version # Isolation level + FB.isc_tpb_nowait # Lock resolution strategy ) FB.init(type_conv=1, concurrency_level=2) class QueryDB(object): def __init__(self, k_conf): self.k_conf = k_conf self.GetConnect() def GetConnect(self): self.connect = None self.db_message = '' if self.k_conf.status_config == krconst.kr_status_config_error: self.db_message = self.k_conf.status_config_message try: self.connect = FB.connect(dsn=self.k_conf.db_ip + ':' + self.k_conf.db_path,
import kinterbasdb import time from random import random import logging kinterbasdb.init(type_conv=0) TIME_FORMAT = "%Y-%m-%d %H:%M:%S" def main(): db = FirebirdDB("localhost:/var/lib/firebird/2.0/data/test.fdb") now = time.time() for i in range(0, 10000): writeDB(db, time.localtime(now + (600 * i))) print i def writeDB(db, t): sql = """ INSERT INTO METEO (TIMESTAMP_UTC, TIMESTAMP_LOCAL, TEMP, TEMP_MIN, TEMP_MIN_TIME, TEMP_MAX, TEMP_MAX_TIME, HUM, WIND, WIND_DIR, WIND_GUST, WIND_GUST_DIR, WIND_GUST_TIME, DEW_POINT, RAIN, RAIN_RATE, RAIN_RATE_TIME, PRESSURE, UV_INDEX) VALUES (%s, %s, %g, %g, %s, %g, %s, %g, %g, %s, %g, %s, %s, %g, %g, %g, %s, %g, %s) """ % ("'%s'" % time.strftime(TIME_FORMAT, t), "'%s'" % time.strftime(TIME_FORMAT, t), random() * 20 - 5, random() * 10 - 10, "'%s'" % time.strftime(TIME_FORMAT, t), random() * 30 + 10, "'%s'" % time.strftime(TIME_FORMAT, t), random() * 100, random() * 10, int(random() * 360), random() * 20, int(random() * 360), "'%s'" % time.strftime(TIME_FORMAT, t), random() * 20, random() * 1000, random() * 5, "'%s'" % time.strftime(TIME_FORMAT, t),
#! /usr/bin/python #-*- coding:utf-8 -*- import wx import kinterbasdb as fdb fdb.init(type_conv=200) import gui class zsalse_frame(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, -1, title) class MyApp(wx.App): def OnInit(self): frame = zsalse_frame(None, u"Z协作营销系统") self.SetTopWindow(frame) frame.Show(True) return True app = MyApp(redirect=False) app.MainLoop()