I wrote the following functions for transferring data from Access to Firebird

def getFirebirdFieldNames(firebird_cursor, tablename): firebird_cursor.execute('select rdb$field_name from rdb$relation_fields where rdb$relation_name=\'%s\' order by rdb$field_position' % (tablename,)) field_names = list() for c in firebird_cursor.fetchall(): field_names.append(c[0]) return field_names def FirebirdDatetime(dt): return '\'%s.%s.%s\'' % (str(dt.day).rjust(2,'0'), str(dt.month).rjust(2,'0'), str(dt.year).rjust(4,'0')) def SelectFromAccessTable(tablename): return 'select * from [' + tablename+']' def InsertToFirebirdTable(tablename, row): values='' #values=values.encode('cp1251', 'replace') # copyrow=[] # print type(values) for i in range(len(row)): #print row[i] #print type(row[i]) #temp='' if (i<len(row)-1): if type(row[i]) == int: temp = str(row[i]) else: if type(row[i]) == str: temp = '\'%s\'' % (row[i],) else: if type(row[i]) == datetime.datetime: temp =FirebirdDatetime(row[i]) else: if type(row[i]) == decimal.Decimal: temp = str(row[i]) else: if row[i]==None: temp='null' values+=temp+', ' else: if type(row[i]) == int: temp = str(row[i]) else: if type(row[i]) == str: temp = '\'%s\'' % (row[i],) else: if type(row[i]) == datetime.datetime: temp =FirebirdDatetime(row[i]) else: if type(row[i]) == decimal.Decimal: temp = str(row[i]) else: if row[i]==None: temp='null' values+=temp print temp return 'insert into '+tablename+' values ('+values+')' def AccessToFirebird(accesstablename, firebirdtablename, accesscursor, firebirdcursor): SelectSql=SelectFromAccessTable(accesstablename) for row in accesscursor.execute(SelectSql): InsertSql=InsertToFirebirdTable(firebirdtablename, row) InsertSql=InsertSql print InsertSql firebirdcursor.execute(InsertSql) 

When the AccessToFirebird function is AccessToFirebird in the main module, the InsertToFirebirdTable function is InsertToFirebirdTable , in which the generated insert requests are displayed on the screen. As can be seen from the output below, temp assigned to row[0] and does not change later, which contradicts the logic of the program (the loop bypasses the entire row and the result should be an insert query with all values ​​passed). Why is this happening and how to make the result fit the goal? I quote the output of the generated queries (the Northwind database in Access)

 1 1 1 1 null null null null null null null null null null null null null null insert into CLIENTS values (1, 1, 1, 1, null, null, null, null, null, null, null, null, null, null, null, null, null, null) 2 2 2 2 null null null null null null null null null null null null null null insert into CLIENTS values (2, 2, 2, 2, null, null, null, null, null, null, null, null, null, null, null, null, null, null) 3 3 3 3 null null null null null null null null null null null null null null insert into CLIENTS values (3, 3, 3, 3, null, null, null, null, null, null, null, null, null, null, null, null, null, null) 4 4 4 4 null null null null null null null null null null null null null null insert into CLIENTS values (4, 4, 4, 4, null, null, null, null, null, null, null, null, null, null, null, null, null, null) 

Closed due to the fact that the participants are off topic: Athari , VenZell , alexis031182 , ixSci , PashaPash 18 May '15 at 10:03 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "Questions asking for help with debugging (" why does this code not work? ") Should include the desired behavior , a specific problem or error, and the minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, complete, repeatable example . " - Athari, VenZell, alexis031182, ixSci, PashaPash
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • eight
    Everything is very clear and readable. Expect a response during the year - moden
  • it just do the fire! long did you insert the code here? - Artem
  • @moden and @Shrek I only have a large output of the generated queries (and then you can not read everything - but only the first 4 queries, in order to understand what is happening). - ivan89

1 answer 1

Some transferable data was of the unicode type, and their processing was not provided for if , so temp retained its value (no new one was assigned).