I managed to connect to the Northwind database (Access) and copy some of the information from it into the created identical database on Firebird. Here is the code that does this:
conAcc = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:\ThirdTask\Northwind.accdb') SqlAccess=conAcc.cursor(); SqlAccess.execute(sql.sql_count_records_clients); CountOfRecords=SqlAccess.fetchone()[0]; print CountOfRecords id=0 conn.begin() cur=conn.cursor() while id<CountOfRecords: id+=1 SqlAccess.execute(sql.sql_allfields_clients, (id,)) clientdict=dict(ident=id, organization=SqlAccess.fetchone()[1]); print clientdict s='' s="INSERT INTO CLIENTS (ID, COMPANY) VALUES" s+="("+str(clientdict['ident'])+", " +"\'"+clientdict['organization']+"\'"+")" print s cur.execute(s) conn.commit() conn.close() conAcc.close();
I bring the sql.py module
# -*- coding: cp1251 -*- sqltables='''SELECT id, name, description, can_add, can_edit, can_delete FROM tables''' sqlfields = '''SELECT fields.position,fields.name,fields.description, data_types.type_id,domains.char_length, fields.can_input,fields.can_edit, fields.show_in_grid,fields.is_mean, fields.autocalculated, fields.required FROM fields JOIN domains ON fields.domain_id = domains.id JOIN data_types ON domains.data_type_id = data_types.id WHERE fields.table_id = ? ORDER BY fields.position ''' sqlconstraints='''SELECT constraints.id, constraints.name, constraint_type, constraints.reference, tables.name FROM constraints LEFT JOIN tables ON constraints.table_id = tables.id WHERE table_id = ? ''' sql_constr_det = '''SELECT fields.name, tables.name FROM constraint_details JOIN fields ON constraint_details.field_id = fields.id JOIN tables ON tables.id=fields.table_id WHERE constraint_id = ? AND tables.id= ? ''' sqlindices = '''SELECT indices.id,indices.name FROM indices WHERE indices.table_id = ? ''' sql_indices_fields = '''SELECT fields.name, index_details.position FROM indices JOIN index_details ON index_id = indices.id JOIN fields ON field_id = fields.id WHERE indices.table_id = ? AND indices.id=?''' sql_indices_descend='''SELECT index_details.descend FROM index_details JOIN indices ON index_details.index_id = indices.id JOIN fields ON field_id = fields.id WHERE indices.table_id = ? AND indices.id = ? AND fields.name = ?''' sql_fields='''SELECT fields.name FROM fields JOIN tables ON tables.id=fields.table_id JOIN constraints ON (constraints.table_id=tables.id and constraints.constraint_type='PRIMARY') JOIn constraint_details ON (constraint_details.constraint_id=constraints.id and constraint_details.field_id=fields.id) WHERE tables.name= ?''' sql_count_records_clients='''SELECT COUNT(*) FROM Customers''' sql_allfields_clients='''SELECT * FROM Customers WHERE ИД=?'''
But as a result of inserting the CLIENTS table information into the COMPANY field, the information is not presented in Cyrillic. How to change the clientdict ['organization'] encoding so that the information is displayed correctly?