Example #1
0
 def tables_and_views_by_col(self, target, cols):
     identifier = {'table_name': target + '%'}
     column_list = ','.join("'%s'" % c for c in cols)
     qry = self.tables_and_views_by_col_qry % column_list.lower()
     curs = self.connection.cursor()
     dbapiext.execute_f(curs, qry, paramstyle=self.paramstyle, **identifier)
     return curs
Example #2
0
 def tables_and_views_by_col(self, target, cols):
     identifier = {'table_name': target + '%'}        
     column_list = ','.join("'%s'" % c for c in cols)
     qry = self.tables_and_views_by_col_qry % column_list.lower()
     curs = self.connection.cursor() 
     dbapiext.execute_f(curs, qry, paramstyle=self.paramstyle, **identifier)
     return curs
Example #3
0
 def tables_and_views(self, target):
     identifier = {'table_name': target + '%'}
     curs = self.connection.cursor()
     dbapiext.execute_f(curs,
                        self.tables_and_views_qry,
                        paramstyle=self.paramstyle,
                        **identifier)
     return curs
Example #4
0
def save_integration(cursor, version, state, result, owner, comment,
                     source_tree_root_id):
    execute_f(cursor, '''
        INSERT INTO integration (version, state, result, owner, comment,
                          source_tree_root_id) VALUES (%X,%X,%X,%X,%X,%X)''',
              version, state, result, owner, comment, source_tree_root_id)
    cursor.connection.commit()
    return get_last_id(cursor)
Example #5
0
def save_job(cursor, result, type_, id_):
    for row in result:
        execute_f(cursor, '''
            INSERT INTO job (name, type, state, result, log, started, elapsed,
                             job_group_id)
            VALUES (%X,%X,%X,%X,%X,%X,%X,%X)''',
                       row['name'], type_, 'finished', row['result'],
                       row['err']+row['out'],row['started'],row['elapsed'], id_)
    cursor.connection.commit()
Example #6
0
def db_job_group_start(cursor, started, elapsed, state, result, log,
                       integration_id, sodd_instance_id):
    execute_f(cursor, '''
        INSERT INTO job_group (started, elapsed, state, result,
                     log, integration_id, sodd_instance_id) VALUES
                     (%X,%X,%X,%X,%X,%X,%X)''',
                   started, elapsed, state, result, log, integration_id,
                   sodd_instance_id)
    cursor.connection.commit()
    return get_last_id(cursor)
Example #7
0
 def _source(self, target, opts):
     identifier = {'text': '%%%s%%' % target.lower()}
     if opts.all:
         identifier['owner'] = '%'
     else:
         identifier['owner'] = self.username
     self.set_operators(identifier)
     curs = self.connection.cursor()
     dbapiext.execute_f(curs, self.source_qry, paramstyle=self.paramstyle, **identifier)
     return curs
Example #8
0
 def columns(self, target, table_name, opts):
     target = self.sql_format_wildcards(target)
     table_name = self.sql_format_wildcards(table_name)
     identifier = {'column_name': target, 'table_name': table_name}
     if opts.all:
         identifier['owner'] = '%'
     else:
         identifier['owner'] = self.username
     self.set_operators(identifier)
     curs = self.connection.cursor()
     dbapiext.execute_f(curs, self.column_qry, paramstyle=self.paramstyle, **identifier)
     return curs
Example #9
0
 def objects(self, target, opts):
     identifier = self.parse_identifier(target)
     if (identifier['owner'] == '%') and (not opts.all):
         identifier['owner'] = self.default_owner()
     self.set_operators(identifier)
     if hasattr(opts, 'reverse') and opts.reverse:
         identifier['sort_direction'] = 'DESC'
     else:
         identifier['sort_direction'] = 'ASC'
     curs = self.connection.cursor()
     dbapiext.execute_f(curs, self.all_object_qry, paramstyle=self.paramstyle, **identifier)
     return curs
Example #10
0
 def update(self, id_, attributes):
     with (yield self.cursor(self.connection, transaction=True)) as cursor:
         cur = dbapiext.execute_f(cursor, 'update %s set %X where id = %X',
                                  self._tablename, attributes, id_)
         if is_future(cur):
             cur = yield cur
     with (yield self.cursor(self.connection)) as cursor:
         cur = dbapiext.execute_f(cursor, 'select %s from %s where id = %X',
                                  self.columns + ['id'], self._tablename,
                                  id_)
         if is_future(cur):
             cur = yield cur
         return DBAPI2Resource.ResourceObject(self, cur.fetchone())
Example #11
0
 def _source(self, target, opts):
     identifier = {'text': '%%%s%%' % target.lower()}
     if opts.all:
         identifier['owner'] = '%'
     else:
         identifier['owner'] = self.username
     self.set_operators(identifier)
     curs = self.connection.cursor()
     dbapiext.execute_f(curs,
                        self.source_qry,
                        paramstyle=self.paramstyle,
                        **identifier)
     return curs
Example #12
0
 def create(self, attributes):
     with (yield self.cursor(self.connection, transaction=True)) as cursor:
         cur = dbapiext.execute_f(cursor, 'insert into %s (%s) values (%X)',
                                  self._tablename, list(attributes.keys()),
                                  list(attributes.values()))
         if is_future(cur):
             cur = yield cur
     with (yield self.cursor(self.connection)) as cursor:
         # XXX assuming id is monotonically increasing
         cur = dbapiext.execute_f(
             cursor, 'select %s from %s order by id desc limit 1',
             self.columns + ['id'], self._tablename)
         if is_future(cur):
             cur = yield cur
         return DBAPI2Resource.ResourceObject(self, cur.fetchone())
Example #13
0
 def objects(self, target, opts):
     identifier = self.parse_identifier(target)
     if (identifier['owner'] == '%') and (not opts.all):
         identifier['owner'] = self.default_owner()
     self.set_operators(identifier)
     if hasattr(opts, 'reverse') and opts.reverse:
         identifier['sort_direction'] = 'DESC'
     else:
         identifier['sort_direction'] = 'ASC'
     curs = self.connection.cursor()
     dbapiext.execute_f(curs,
                        self.all_object_qry,
                        paramstyle=self.paramstyle,
                        **identifier)
     return curs
Example #14
0
 def columns(self, target, table_name, opts):
     target = self.sql_format_wildcards(target)
     table_name = self.sql_format_wildcards(table_name)
     identifier = {'column_name': target, 'table_name': table_name}
     if opts.all:
         identifier['owner'] = '%'
     else:
         identifier['owner'] = self.username
     self.set_operators(identifier)
     curs = self.connection.cursor()
     dbapiext.execute_f(curs,
                        self.column_qry,
                        paramstyle=self.paramstyle,
                        **identifier)
     return curs
Example #15
0
 def delete(self, id_):
     with (yield self.cursor(self.connection, transaction=True)) as cursor:
         cur = dbapiext.execute_f(cursor, 'delete from %s where id = %X',
                                  self._tablename, id_)
         if is_future(cur):
             cur = yield cur
         return cur.rowcount
Example #16
0
 def exists(self, id_):
     with (yield self.cursor(self.connection)) as cursor:
         cur = dbapiext.execute_f(cursor, 'select 1 from %s where id = %X',
                                  self._tablename, id_)
         if is_future(cur):
             cur = yield cur
         return cur.fetchone() is not None
Example #17
0
 def list_(self):
     with (yield self.cursor(self.connection)) as cursor:
         cur = dbapiext.execute_f(cursor, 'select %s from %s',
                                  self.columns + ['id'], self._tablename)
         if is_future(cur):
             cur = yield cur
         rows = cur.fetchall()
         return [DBAPI2Resource.ResourceObject(self, row) for row in rows]
Example #18
0
 def list_count(self):
     with (yield self.cursor(self.connection)) as cursor:
         cur = dbapiext.execute_f(cursor, "select count(1) from %s",
                                  self._tablename)
         if is_future(cur):
             cur = yield cur
         rows = cur.fetchone()
         return rows[0]
Example #19
0
 def read(self, id_):
     with (yield self.cursor(self.connection)) as cursor:
         cur = dbapiext.execute_f(cursor, 'select %s from %s where id = %X',
                                  self.columns + ['id'], self._tablename,
                                  id_)
         if is_future(cur):
             cur = yield cur
         row = cur.fetchone()
         if not row:
             return None
         return DBAPI2Resource.ResourceObject(self, row)
Example #20
0
 def _create_table(self):
     types = [
         self._types_mapping[self._schema.propinfo(c)['type']] +
         (' not null' if c in self._schema.__required__ else '')
         for c in self.columns
     ]
     column_defs = [self._create_primary_key()] + \
         ['{} {}'.format(c, t) for c, t in zip(self.columns, types)]
     with (yield self.cursor(self.connection, transaction=True)) as cursor:
         cur = dbapiext.execute_f(cursor,
                                  'create table if not exists %s (%s)',
                                  self._tablename, column_defs)
         if is_future(cur):
             yield cur
Example #21
0
 def list_(self, limit=0, page=0):
     with (yield self.cursor(self.connection)) as cursor:
         if limit > 0:
             start = abs(page) * limit
             cur = dbapiext.execute_f(
                 cursor,
                 "select %s from %s limit %d offset %d",
                 self.columns + ["id"],
                 self._tablename,
                 limit,
                 start,
             )
         else:
             cur = dbapiext.execute_f(
                 cursor,
                 "select %s from %s",
                 self.columns + ["id"],
                 self._tablename,
             )
         if is_future(cur):
             cur = yield cur
         rows = cur.fetchall()
         return [DBAPI2Resource.ResourceObject(self, row) for row in rows]
Example #22
0
def db_job_group_finish(cursor, id_, elapsed, result, log, state='finished'):
    execute_f(cursor, '''
        UPDATE job_group SET elapsed=%X, state=%X, result=%X, log=%X WHERE
                        id=%X''', elapsed, state, result, log, id_)
    cursor.connection.commit()
Example #23
0
def save_sodd_instance(cursor, name, machine):
    execute_f(cursor, '''
        INSERT INTO sodd_instance (name, machine) VALUES (%X,%X)''',
              name, machine)
    cursor.connection.commit()
    return get_last_id(cursor)
Example #24
0
 def tables_and_views(self, target):
     identifier = {'table_name': target + '%'}
     curs = self.connection.cursor()
     dbapiext.execute_f(curs, self.tables_and_views_qry, paramstyle=self.paramstyle, **identifier)
     return curs
Example #25
0
def save_source_tree_root(cursor, source_location):
    execute_f(cursor, '''
        INSERT INTO source_tree_root (source_location) VALUES (%X)''',
              source_location)
    cursor.connection.commit()
    return get_last_id(cursor)