pysqlite2无法往数据库接入数据,请指点

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

pysqlite2无法往数据库接入数据,请指点

吕新志
表结构
CREATE TABLE people
(
    name_last   varchar(20),
    age         integer
);


以下是SQL语句
# -*- coding: utf-8 -*-
#from pysqlite2 import dbapi2 as sqlite
import sqlite

con=sqlite.connect("xn.db")

cur=con.cursor()

#cur.execute("SELECT * FROM item_type where code >5")

newPeople=(
    ('Lebed',53),
    ('Zhirinovsky',57),
)
#for person in newPeople:
#    cur.execute("INSERT INTO people (name_last,age) VALUES (?,?)",person)
cur.execute("INSERT INTO people (name_last) VALUES (?)",str("aa"))
con.commit()
#data = cur.fetchall()
#for i in data:
#    print i
#
#cur.close()


Traceback (most recent call last):
  File "D:\workspace\wx\src\consqlite.py", line 17, in ?
    cur.execute("INSERT INTO people (name_last) VALUES (?)",str("aa"))
  File "C:\Python24\Lib\site-packages\sqlite\main.py", line 255, in execute
    self.rs = self.con.db.execute(SQL % parms)
TypeError: not all arguments converted during string formatting

--
          ,        ," 1+
                      /(        )`" 1+
                      \ \___   / |" 1+
                      /- _  `-/  '" 1+
                     (/\/ \ \   /\" 1+
                     / /   | `    \" 1+
                     O O   ) /    |" 1+
                     `-^--'`<     '" 1+
                    (_.)  _  )   /" 1+
                     `.___/`    /" 1+
                       `-----' /" 1+
          <----.     __ / __   \" 1+
          <----|====O)))==) \) /====" 1+
          <----'    `--' `.__,' \" 1+
                       |        |" 1+
                        \       /       /\" 1+
                   ______( (_  / \______/" 1+
                 ,'  ,-----'   |" 1+
                 `--{__________)"
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: pysqlite2无法往数据库接入数据,请指点

weizi-2
Mail
python-chinese,你好
这样写就可以了。
cur.execute("INSERT INTO people (name_last) VALUES (?)",(str("aa"),))
 
2007-12-27
----- Original Message -----
Sent: 2007-12-27, 11:02:45
Subject: [python-chinese] pysqlite2无法往数据库接入数据,请指点

表结构
CREATE TABLE people
(
    name_last varchar(20),
    age integer
);


以下是SQL语句
# -*- coding: utf-8 -*-
#from pysqlite2 import dbapi2 as sqlite
import sqlite

con=sqlite.connect("xn.db")

cur=con.cursor()

#cur.execute("SELECT * FROM item_type where code >5")

newPeople=(
    ('Lebed',53),
    ('Zhirinovsky',57),
)
#for person in newPeople:
# cur.execute("INSERT INTO people (name_last,age) VALUES (?,?)",person)
cur.execute("INSERT INTO people (name_last) VALUES (?)",str("aa"))
con.commit()
#data = cur.fetchall()
#for i in data:
# print i
#
#cur.close()


Traceback (most recent call last):
  File "D:\workspace\wx\src\consqlite.py", line 17, in ?
    cur.execute("INSERT INTO people (name_last) VALUES (?)",str("aa"))
  File "C:\Python24\Lib\site-packages\sqlite\main.py", line 255, in execute
    self.rs = self.con.db.execute(SQL % parms)
TypeError: not all arguments converted during string formatting

--
          , ," 1+
                /( )`" 1+
                \ \___ / |" 1+
                /- _ `-/ '" 1+
               (/\/ \ \ /\" 1+
               / / | ` \" 1+
               O O ) / |" 1+
               `-^--'`< '" 1+
              (_.) _ ) /" 1+
               `.___/` /" 1+
                 `-----' /" 1+
    <----. __ / __ \" 1+
    <----|====O)))==) \) /====" 1+
    <----' `--' `.__,' \" 1+
                 | |" 1+
                  \ / /\" 1+
             ______( (_ / \______/" 1+
           ,' ,-----' |" 1+
           `--{__________)"
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: pysqlite2无法往数据库接入数据,请指点

weizi-2
In reply to this post by 吕新志
Mail
python-chinese,你好
这样写就可以了。
cur.execute("INSERT INTO people (name_last) VALUES (?)",(str("aa"),))
 
2007-12-27
----- Original Message -----
Sent: 2007-12-27, 11:02:45
Subject: [python-chinese] pysqlite2无法往数据库接入数据,请指点

表结构
CREATE TABLE people
(
    name_last varchar(20),
    age integer
);


以下是SQL语句
# -*- coding: utf-8 -*-
#from pysqlite2 import dbapi2 as sqlite
import sqlite

con=sqlite.connect("xn.db")

cur=con.cursor()

#cur.execute("SELECT * FROM item_type where code >5")

newPeople=(
    ('Lebed',53),
    ('Zhirinovsky',57),
)
#for person in newPeople:
# cur.execute("INSERT INTO people (name_last,age) VALUES (?,?)",person)
cur.execute("INSERT INTO people (name_last) VALUES (?)",str("aa"))
con.commit()
#data = cur.fetchall()
#for i in data:
# print i
#
#cur.close()


Traceback (most recent call last):
  File "D:\workspace\wx\src\consqlite.py", line 17, in ?
    cur.execute("INSERT INTO people (name_last) VALUES (?)",str("aa"))
  File "C:\Python24\Lib\site-packages\sqlite\main.py", line 255, in execute
    self.rs = self.con.db.execute(SQL % parms)
TypeError: not all arguments converted during string formatting

--
          , ," 1+
                /( )`" 1+
                \ \___ / |" 1+
                /- _ `-/ '" 1+
               (/\/ \ \ /\" 1+
               / / | ` \" 1+
               O O ) / |" 1+
               `-^--'`< '" 1+
              (_.) _ ) /" 1+
               `.___/` /" 1+
                 `-----' /" 1+
    <----. __ / __ \" 1+
    <----|====O)))==) \) /====" 1+
    <----' `--' `.__,' \" 1+
                 | |" 1+
                  \ / /\" 1+
             ______( (_ / \______/" 1+
           ,' ,-----' |" 1+
           `--{__________)"
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese