i thank you all, first of al ill change my dictinary variable name :) then ill use %s and %d . and thanks for other examples,these examples enchance my python-way thinking. :)
On 8/12/05, Scott David Daniels <[EMAIL PROTECTED]> wrote: > Paolino wrote: > > sinan . wrote: > > > >> hi all, > >> i have a string and int values in same dictionary like this > >> dict = {'str_name': 'etc' , 'int_name' : 112 } > Bad idea to call this "dict" -- that is a system-defined name > for the dictionary type. I'll use "holder" below. > > >> the error occures when do this > >> SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('" + dict['str_name'] + "', > >> '" + dict['int_name'] + "')" > ^^ I suspect this should be: > SQL = "INSERT INTO TABLENAME(AH, BH) VALUES (... > >> cursor.execute(SQL) > >> python does not accep dict['int_name'] in SQL variable but when i > >> convert this variable to the str , python accepts but i cannot insert > >> that into database because database only accept int in `BH ` > >> thanks. > > > Try use: > > SQL = "INSERT INTO (`AH`, `BH` ) VALUES > > ('%s,%d)"%(dict['str_name'],dict['int_name']) > This will work, but the DB interface allows you to leave the > variable formatting to it. Depending on the parameter style > your DB interface supports, you may use at least one of: > > cursor.execute("INSERT INTO TABLENAME(AH, BH) VALUES(?, ?)", > [(holder['str_name'], holder['int_name'])]) > or > cursor.execute("INSERT INTO TABLENAME(AH, BH) VALUES(:1, :2)", > [(holder['str_name'], holder['int_name'])]) > ### I think, it _might_ be ...(0, :1)", > or > cursor.execute("INSERT INTO TABLENAME(AH, BH) " > "VALUES(:str_name, :int_name)", > holder) > > --Scott David Daniels > [EMAIL PROTECTED] > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list