def get_table_columns(cur, tablename, exclude_columns=[]): import utool as ut colnames_ = ut.get_table_columnname_list(cur, tablename) colnames = tuple([colname for colname in colnames_ if colname not in exclude_columns]) row_list = ut.get_table_rows(cur, tablename, colnames, unpack=False) column_list = zip(*row_list) return column_list
def get_table_csv(cur, tablename, exclude_columns=[]): """ Conveinience: Converts a tablename to csv format Args: tablename (str): exclude_columns (list): Returns: str: csv_table CommandLine: python -m ibeis.control.SQLDatabaseControl --test-get_table_csv Example: >>> # ENABLE_DOCTEST >>> from ibeis.control.SQLDatabaseControl import * # NOQA >>> # build test data >>> import ibeis >>> ibs = ibeis.opendb('testdb1') >>> db = ibs.db >>> tablename = ibeis.const.NAME_TABLE >>> exclude_columns = [] >>> # execute function >>> csv_table = db.get_table_csv(tablename, exclude_columns) >>> # verify results >>> result = str(csv_table) >>> print(result) """ import utool as ut colnames_ = ut.get_table_columnname_list(cur, tablename) colnames = tuple([colname for colname in colnames_ if colname not in exclude_columns]) row_list = ut.get_table_rows(cur, tablename, colnames, unpack=False) column_list = zip(*row_list) #=None, column_list=[], header='', column_type=None #import utool as ut #column_list, column_names = db.get_table_column_data(tablename, exclude_columns) # remove column prefix for more compact csvs column_lbls = [name.replace(tablename[:-1] + '_', '') for name in colnames] #header = db.get_table_csv_header(tablename) header = '' csv_table = ut.make_csv_table(column_list, column_lbls, header) return csv_table
def get_item_resource(): """ from zotero_helpers import * """ #item_list = zotero.search('Distinctive Image Features from Scale-Invariant Keypoints') #item_list = zotero.search('lowe_distinctive_2004') zotero_fpath = get_zotero_path() from os.path import join # FIND THE BIBTEX ITEMID import sqlite3 bibsql = join(zotero_fpath, 'betterbibtex.sqlite') con = sqlite3.connect(bibsql) cur = con.cursor() # ut.util_sqlite.get_tablenames(cur) #ut.util_sqlite.print_database_structure(cur) itemID = ut.util_sqlite.get_table_rows(cur, 'keys', 'itemID', where='citekey=?', params='lowe_distinctive_2004') con.close() ############### zotero = get_libzotero() item = zotero.index[itemID] cur = zotero.cur # NOQA zotero.index[1434].title # ENTIRE DATABASE INFO ut.print_database_structure(cur) # FIND WHERE ATTACHMENT EXITS for tablename in ut.get_tablenames(cur): try: x = ut.get_table_csv(cur, tablename).find('ijcv04.pdf') except Exception as ex: continue if x != -1: print(tablename) print(x) tablename = 'itemDataValues' print(ut.truncate_str(ut.get_table_csv(cur, tablename), maxlen=5000)) tablename = 'itemDataValues' column_list = ut.get_table_columns(cur, tablename) import six for column in column_list: for rowx, row in enumerate(column): if isinstance(row, six.string_types): if row.find('ijcv04.pdf') > -1: print(rowx) print(row) valueID = column_list[0][3003] value = column_list[1][3003] ut.util_sqlite.get_table_rows(cur, 'itemData', None, where='valueID=?', params=valueID, unpack=False) ### #ut.rrrr() tablename = 'itemAttachments' colnames = tuple(ut.get_table_columnname_list(cur, tablename)) print(ut.get_table_csv(cur, tablename, ['path'])) _row_list = ut.get_table_rows(cur, tablename, 'itemID', unpack=True) ut.get_table_rows(cur, tablename, colnames, unpack=False) ut.get_table_num_rows(cur, tablename) itemID = ut.util_sqlite.get_table_rows(cur, tablename, colnames, where='itemID=?', params=itemID, unpack=False)