Ska.DBI provides simple methods for database access and data insertion. Features:
Try using the numpy.tolist() to convert to native python type. DBI’s can’t typically handle numpy vals.
Bases: object
Database interface class.
Example usage:
db = DBI(dbi='sqlite', server=dbfile, numpy=False, verbose=True)
db = DBI(dbi='sybase', server='sybase', user='aca_ops', database='aca')
db = DBI(dbi='sybase') # Use defaults (same as above)
Parameters: |
|
---|---|
Return type: | DBI object |
Commit transactions
Run self.cursor.execute(expr, vals) with possibility of verbose output and commit.
Multiple commands can by executed by separating them with a semicolon at the end of a line. If vals are supplied they will be applied to each of the commands.
Parameters: |
|
---|---|
Return type: | None |
Return a generator that will fetch one row at a time after executing with args.
Example usage:
for row in db.fetch(expr, vals):
print row['column']
Parameters: |
|
---|---|
Return type: | Generator that will get one row of database as dict() via next() |
Fetch all rows after executing args.
Example usage:
rows = db.fetchall(expr, vals)
print rows[1:5]['column']
Parameters: |
|
---|---|
Return type: | All rows of database as numpy.rec.recarray or list of dicts, depending on self.numpy |
Fetch one row after executing args. This always gets the first row of the SQL query. Use Ska.DBI.fetch() to get multiple rows one at a time.
Example usage:
row = db.fetchone(expr, vals)
print row['column']
Parameters: |
|
---|---|
Return type: | One row of database as dict() |
Insert data row into table tablename.
Parameters: |
|
---|---|
Return type: | None |