labpack/databases/sql.py
def _construct_inserts(self, record, new_columns, rename_columns, retype_columns, resize_columns):

        ''' a helper method for constructing the insert kwargs for a record '''

        insert_kwargs = {}

        for key, value in new_columns.items():

        # retrieve value for key (or from old key name)
            if key in rename_columns.keys():
                record_value = getattr(record, rename_columns[key], None)
            else:
                record_value = getattr(record, key, None)

        # attempt to convert datatype
            if record_value:
                if key in retype_columns.keys():
                    try:
                        old_list = False
                        if isinstance(record_value, bytes):
                            record_value = pickle.loads(record_value)
                            old_list = True
                        if retype_columns[key] == 'boolean':
                            record_value = bool(record_value)
                        elif retype_columns[key] == 'string':
                            if old_list:
                                record_value = ','.join(record_value)
                            else:
                                record_value = str(record_value)
                        elif retype_columns[key] == 'integer':
                            if old_list:
                                record_value = int(record_value[0])
                            else:
                                record_value = int(record_value)
                        elif retype_columns[key] == 'float':
                            if old_list:
                                record_value = float(record_value[0])
                            else:
                                record_value = float(record_value)
                        elif retype_columns[key] == 'list':
                            if isinstance(record_value, str):
                                record_value = pickle.dumps(record_value.split(','))
                            else:
                                record_value = pickle.dumps([record_value])
                    except:
                        record_value = None
        
        # attempt to resize string data 
                if key in resize_columns.keys():
                    max_length = resize_columns[key]
                    try:
                        if len(record_value) > max_length:
                            record_value = record_value[0:max_length]
                    except:
                        record_value = None

                insert_kwargs[key] = record_value

        return insert_kwargs
 a helper method for constructing the insert kwargs for a record 
a helper method for constructing the insert kwargs for a record
a helper method for constructing the insert kwargs for a record
def _construct_inserts(self, record, new_columns, rename_columns, retype_columns, resize_columns):
        insert_kwargs = {}
        for key, value in new_columns.items():
            if key in rename_columns.keys():
                record_value = getattr(record, rename_columns[key], None)
            else:
                record_value = getattr(record, key, None)
            if record_value:
                if key in retype_columns.keys():
                    try:
                        old_list = False
                        if isinstance(record_value, bytes):
                            record_value = pickle.loads(record_value)
                            old_list = True
                        if retype_columns[key] == 'boolean':
                            record_value = bool(record_value)
                        elif retype_columns[key] == 'string':
                            if old_list:
                                record_value = ','.join(record_value)
                            else:
                                record_value = str(record_value)
                        elif retype_columns[key] == 'integer':
                            if old_list:
                                record_value = int(record_value[0])
                            else:
                                record_value = int(record_value)
                        elif retype_columns[key] == 'float':
                            if old_list:
                                record_value = float(record_value[0])
                            else:
                                record_value = float(record_value)
                        elif retype_columns[key] == 'list':
                            if isinstance(record_value, str):
                                record_value = pickle.dumps(record_value.split(','))
                            else:
                                record_value = pickle.dumps([record_value])
                    except:
                        record_value = None
                if key in resize_columns.keys():
                    max_length = resize_columns[key]
                    try:
                        if len(record_value) > max_length:
                            record_value = record_value[0:max_length]
                    except:
                        record_value = None
                insert_kwargs[key] = record_value
        return insert_kwargs
def _construct_inserts ( self , record , new_columns , rename_columns , retype_columns , resize_columns ) : insert_kwargs = { } for key , value in new_columns . items ( ) : if key in rename_columns . keys ( ) : record_value = getattr ( record , rename_columns [ key ] , None ) else : record_value = getattr ( record , key , None ) if record_value : if key in retype_columns . keys ( ) : try : old_list = False if isinstance ( record_value , bytes ) : record_value = pickle . loads ( record_value ) old_list = True if retype_columns [ key ] == 'boolean' : record_value = bool ( record_value ) elif retype_columns [ key ] == 'string' : if old_list : record_value = ',' . join ( record_value ) else : record_value = str ( record_value ) elif retype_columns [ key ] == 'integer' : if old_list : record_value = int ( record_value [ 0 ] ) else : record_value = int ( record_value ) elif retype_columns [ key ] == 'float' : if old_list : record_value = float ( record_value [ 0 ] ) else : record_value = float ( record_value ) elif retype_columns [ key ] == 'list' : if isinstance ( record_value , str ) : record_value = pickle . dumps ( record_value . split ( ',' ) ) else : record_value = pickle . dumps ( [ record_value ] ) except : record_value = None if key in resize_columns . keys ( ) : max_length = resize_columns [ key ] try : if len ( record_value ) > max_length : record_value = record_value [ 0 : max_length ] except : record_value = None insert_kwargs [ key ] = record_value return insert_kwargs
a helper method for constructing the insert kwargs for a record
a helper method for constructing the insert kwargs for a record
''' a helper method for constructing the insert kwargs for a record ''' # retrieve value for key (or from old key name) # attempt to convert datatype # attempt to resize string data 
self
record
new_columns
rename_columns
retype_columns
resize_columns