Ejemplo n.º 1
0
def open(name, flags='r', mode=0666):
    """Open the specified database, flags is one of c to create
    it, if it does not exist, n to create a new one (will destroy
    old contents), r to open it read-only and w to open it read-
    write. Appending 'f' to the flags opens the database in fast
    mode, where updates are not written to the database
    immediately. Use the sync() method to force a write."""
    create = 0
    if name.endswith('.e32dbm'):
        filename = unicode(name)
    else:
        filename = unicode(name + '.e32dbm')

    if flags[0] not in 'cnrw':
        raise TypeError, "First flag must be one of c, n, r, w."
    if flags[0] == 'c' and not os.path.exists(filename):
        create = 1
    if flags[0] == 'n':
        create = 1
    db = e32db.Dbms()
    if create:
        db.create(filename)
        db.open(filename)
        db.execute(
            u"CREATE TABLE data (hash integer, key LONG VARCHAR, value LONG VARCHAR)"
        )
        # The funny separate hash column is needed because an index
        # for a truncated column can't be created with the SQL
        # interface.
        db.execute(u"CREATE INDEX hash_idx ON data (hash)")
    else:
        db.open(filename)
    return e32dbm(flags, db)
 def __init__(self, db_name):
     try:
         self.native_db = e32db.Dbms()
         self.native_db.open(db_name)
     except:
         self.native_db.create(db_name)
         self.native_db.open(db_name)
         self.native_db.execute(SportsDiaryEntry.sql_create)
Ejemplo n.º 3
0
 def __init__(self, dbpath):
     self.db = e32db.Dbms()
     self.dbv = e32db.Db_view()
     self.reset_counters()
     try:
         self.db.open(unicode(dbpath))
     except:
         self.db.create(unicode(dbpath))
         self.db.open(unicode(dbpath))
Ejemplo n.º 4
0
    def __init__(self):
        # Database stuff start
        trapsconfigdb = u'e:\\trapsconfig.db'
        testdb = u'e:\\test.db'
        self.db = e32db.Dbms()
        try:
            self.db.open(testdb)
        except:
            self.db.create(testdb)
            self.db.open(testdb)

        try:
            butterflydb.Captures.create_table(self.db);
        except:
            pass
        try:
            butterflydb.Traps.create_table(self.db);
        except:
            pass
        butterflydb.TrapsPopulate() # populates trapsconfig.{db,txt}
        self.positions_db = e32db.Dbms()
        self.positions_db.open(trapsconfigdb)
        # Databse stuff end
        
        self.last_index = 0
        self.capture_app = capture.CaptureApp(self, self.db)
        self.trap_app = trap.TrapApp(self, self.db)
        self.trap_app.child_db = self.capture_app
        self.capture_app.parent_db = self.trap_app.db
        self.site_ima_app = site_ima.SiteImaApp(self, self.positions_db)
        self.xy_position_app = xy_position.XYPositionApp(self, self.positions_db)
        self.attachment_app = attachment.AttachmentApp(self, self.db)
        self.app_lock = e32.Ao_lock()
        self.short_cut = 0
        # Set exit key handler
        appuifw.app.exit_key_handler = self.exit_key_handler
        # Create the tabs
        appuifw.app.set_tabs([u'Site:IMA', u'X,Y:Position', u'Visits',
                              u'Captures', u'Attachments'], self.handle_tab)
        # Set app.body to app1 (for start of script)
        self.handle_tab(0)
        self.user = u'None'
Ejemplo n.º 5
0
    def __init__(self):
        self.db = e32db.Dbms()
        try:
            self.db.open(DB_LOC)
        except:  #doesn't exist
            self.db.create(DB_LOC)
            self.db.open(DB_LOC)
        create = u"create table bundles \
(id counter, \
bundle_flags integer, \
priority integer, \
srr_flags integer, \
source varchar, \
dest varchar, \
replyto varchar, \
custodian varchar, \
prevhop varchar, \
creation_secs integer, \
creation_seqno integer, \
expiration integer, \
payload_file varchar, \
time integer)"

        create_send_bundles = u"create table outbundles \
(id counter, \
dest varchar, \
payload_file varchar, \
sent integer)"

        for com in [create, create_send_bundles]:
            self.db.begin()
            try:
                self.db.execute(com)
                self.db.commit()
            except Exception, e:  #already created exception
                self.db.rollback()
Ejemplo n.º 6
0
            t = DBV.col_type(1 + j)
            print "Column type: %d" % t
            if t != 15:
                print "Raw value: %s" % repr(DBV.col_raw(1 + j))
            if t == 10:
                print "Raw time: %s" % repr(DBV.col_rawtime(1 + j))
                print "Formatted: %s" % e32db.format_rawtime(
                    DBV.col_rawtime(1 + j))

        data.append(tuple(line))
        DBV.next_line()
    del DBV
    return data


db = e32db.Dbms()
FILE = u'c:\\bardb'
if os.path.isfile(FILE):
    os.remove(FILE)
db.create(FILE)
db.open(FILE)
db.execute(u'create table data (a long varchar, b integer)')
db.execute(u"insert into data values('" + ('x' * 10) + "',42)")
print query(db, u'select * from data')
#db.execute(u"insert into data values('"+('x'*100)+"',42)")
#print query(db,u'select * from data')
#db.execute(u"insert into data values('"+('x'*200)+"',42)")
#print query(db,u'select * from data')
#db.execute(u"insert into data values('"+('x'*300)+"',42)")
#print query(db,u'select * from data')
#db.execute(u"insert into data values('"+('x'*3000)+"',42)")
 def __init__(self, method_name='runTest'):
     unittest.TestCase.__init__(self, methodName=method_name)
     self.db_file = u'c:\\data\\temp_db.db'
     self.db = e32db.Dbms()
     self.db.create(self.db_file)