Home > other >  Mysql and sqlite3 query problem for many times, we had several times not fix
Mysql and sqlite3 query problem for many times, we had several times not fix

Time:09-25

Two mysql tables: table1 and table2, two tables at the same id value, aim is to find out the data in a mysql table table1, then detected and mysql in table3 sqlite3 watch table1 biaoti, same company, filename kanwu value field, with the value that the filename to update the mysql downpath values in table table2, now the first step has been completed, the last step to update table2 downpath value errors, it's strange that TypeError: not all the arguments converted during string formatting
 
The import time
The import urllib. Request
The import urllib. Parse
The import sqlite3
The import pymysql

If __name__=="__main__" :
Connmysql=pymysql. Connect (user='root' and password='123456', the database='empiredd' charset='utf8')
Cursormysql=connmysql. Cursor ()
='select query id, title, company, qikanname from table1'
Cursormysql. Execute (query)
For (id, title, company, qikanname) in cursormysql:
Print (id, title, company, qikanname)
Conn=sqlite3. Connect (r "E: \ web \ SpiderResult db3")
Cursor=conn. Cursor ()
SQL="select filename from table3 the where biaoti=? And the company=? And kanwu=?"
Cursor. The execute (SQL, title, company, qikanname))
Values=cursor. Fetchone ()
Print (values [0])
Print (id)
Cursormysql. Execute (' update table2 set downpath=? Where id=? '(values [0], id))
MIT ()
connmysql.comCursor. The close ()
Conn. Close ()
Cursormysql. Close ()
Connmysql. Close ()

Error is cursormysql execute (' update table2 set downpath=? Where id=? '(values [0], id)), very strange

CodePudding user response:

Website seems to have automatic transcoding, source code is as follows:


The import time
The import urllib. Request
The import urllib. Parse
The import sqlite3
The import pymysql



If __name__=="__main__" :
Connmysql=pymysql. Connect (user='root' and password='123456', the database='empiredd' charset='utf8')
Cursormysql=connmysql. Cursor ()
='select query id, title, company, qikanname from table1'
Cursormysql. Execute (query)
For (id, title, company, qikanname) in cursormysql:
Print (id, title, company, qikanname)
Conn=sqlite3. Connect (r "E: \ web \ SpiderResult db3")
Cursor=conn. Cursor ()
SQL="select filename from table3 the where biaoti=? And the company=? And kanwu=?"
Cursor. The execute (SQL, title, company, qikanname))
Values=cursor. Fetchone ()
Print (values [0])
Print (id)
Cursormysql. Execute (' update table2 set downpath=? Where id=? '(values [0], id))
MIT ()
connmysql.comCursor. The close ()
Conn. Close ()
Cursormysql. Close ()
Connmysql. Close ()

CodePudding user response:

Print (values [0]) is the result of the STR type, the value of wxrokl4xnp2. PDF
Print (id) is the result of 60, these two values are correct,

CodePudding user response:

Cursormysql. Execute (' update table2 set downpath=? Where id=? '(values [0], id))

Change

Cursormysql. Execute (' update table2 set downpath=? Where id=? '(values [0] [0], id))


Because values [0] is the first record of the result set, values [0] [0] is the first record that the value of the filename,

CodePudding user response:

In principle should not be an error, you have? Replaced with % s have a look, and the complete error message to be sent
  • Related