473,657 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sqlite3 error

Here's my script:

import sqlite3

con = sqlite3.connect ('labdb')
cur = con.cursor()
cur.executescri pt('''
DROP TABLE IF EXISTS Researchers;
CREATE TABLE Researchers (
researcherID varchar(9) PRIMARY KEY NOT NULL,
birthYear int(4) DEFAULT NULL,
birthMonth int(2) DEFAULT NULL,
birthDay int(2) DEFAULT NULL,
birthCountry varchar(50) DEFAULT NULL,
birthState char(2) DEFAULT NULL,
birthCity varchar(50) DEFAULT NULL,
nameFirst varchar(50) NOT NULL,
nameLast varchar(50) NOT NULL,
nameGiven varchar(255) DEFAULT NULL,
);
''')

And here's the error:

Traceback (most recent call last):
File "C:\Python25\my scripts\labdb\d btest.py", line 19, in <module>
''')
OperationalErro r: near ")": syntax error
>>>
My script looks just like the example in the docs, so I'm not sure what
I'm doing wrong. The error message seems like it should be easy to
figure out, but all I did was close the triple quotes and then close the
parentheses, just like the example.

Hope someone can shed some light on this! :)
Sep 27 '06 #1
38 2808
import sqlite3
>
con = sqlite3.connect ('labdb')
cur = con.cursor()
cur.executescri pt('''
DROP TABLE IF EXISTS Researchers;
CREATE TABLE Researchers (
researcherID varchar(9) PRIMARY KEY NOT NULL,
birthYear int(4) DEFAULT NULL,
birthMonth int(2) DEFAULT NULL,
birthDay int(2) DEFAULT NULL,
birthCountry varchar(50) DEFAULT NULL,
birthState char(2) DEFAULT NULL,
birthCity varchar(50) DEFAULT NULL,
nameFirst varchar(50) NOT NULL,
nameLast varchar(50) NOT NULL,
nameGiven varchar(255) DEFAULT NULL,
);
''')

And here's the error:

Traceback (most recent call last):
File "C:\Python25\my scripts\labdb\d btest.py", line 19, in <module>
''')
OperationalErro r: near ")": syntax error
>>>

My script looks just like the example in the docs, so I'm not sure what
I'm doing wrong. The error message seems like it should be easy to
figure out, but all I did was close the triple quotes and then close the
parentheses, just like the example.

Hope someone can shed some light on this! :)
My guess would be the extra comma on the nameGiven line...most
SQL engines I've used would choke on that

- nameGiven varchar(255) DEFAULT NULL,
+ nameGiven varchar(255) DEFAULT NULL
-tkc

Sep 27 '06 #2
Tim Chase wrote:
My guess would be the extra comma on the nameGiven line...most SQL
engines I've used would choke on that

- nameGiven varchar(255) DEFAULT NULL,
+ nameGiven varchar(255) DEFAULT NULL

You're right! I think that must have been leftover from when it wasn't
the last line in the query. Thanks!
Sep 27 '06 #3

John Salerno wrote:
CREATE TABLE Researchers (
researcherID varchar(9) PRIMARY KEY NOT NULL,
birthYear int(4) DEFAULT NULL,
birthMonth int(2) DEFAULT NULL,
birthDay int(2) DEFAULT NULL,
birthCountry varchar(50) DEFAULT NULL,
birthState char(2) DEFAULT NULL,
birthCity varchar(50) DEFAULT NULL,
nameFirst varchar(50) NOT NULL,
nameLast varchar(50) NOT NULL,
nameGiven varchar(255) DEFAULT NULL,
A bit OT, but one answer to the "can you make a living with just
Python" question is "Yup, tool of choice for rummaging in and fixing
data that's been mangled by users cramming it into dodgy data models"
:-)

(1) Consider that some countries have states/provinces with 3-letter
abbreviations (e.g. Australia) or no abbreviation than I'm aware of in
a Latin alphabet (e.g. China).

(2) It's not apparent how you would use the first, last, and given
names columns, especially with two of them being "not null". Consider
how you would store e.g.:
J Edgar Hoover
DJ Delorie
Sukarno
35
Maggie Cheung Man-Yuk
Molnar Janos
Fatimah binte Rahman
Zhang Manyu

Cheers,
John

Sep 27 '06 #4
John Machin wrote:
John Salerno wrote:
>CREATE TABLE Researchers (
researcherID varchar(9) PRIMARY KEY NOT NULL,
birthYear int(4) DEFAULT NULL,
birthMonth int(2) DEFAULT NULL,
birthDay int(2) DEFAULT NULL,
birthCountry varchar(50) DEFAULT NULL,
birthState char(2) DEFAULT NULL,
birthCity varchar(50) DEFAULT NULL,
nameFirst varchar(50) NOT NULL,
nameLast varchar(50) NOT NULL,
nameGiven varchar(255) DEFAULT NULL,

A bit OT, but one answer to the "can you make a living with just
Python" question is "Yup, tool of choice for rummaging in and fixing
data that's been mangled by users cramming it into dodgy data models"
:-)

(1) Consider that some countries have states/provinces with 3-letter
abbreviations (e.g. Australia) or no abbreviation than I'm aware of in
a Latin alphabet (e.g. China).
Good point. I guess since this program is for my own use, I just figured
I could stick with the American style abbreviation. But it's not as if I
actually considered that this wouldn't always work, so it's good to be
aware of the issue.
(2) It's not apparent how you would use the first, last, and given
names columns, especially with two of them being "not null". Consider
how you would store e.g.:
J Edgar Hoover
DJ Delorie
Sukarno
35
Maggie Cheung Man-Yuk
Molnar Janos
Fatimah binte Rahman
Zhang Manyu
Not sure I follow you on some of these examples. In the case of J Edgar
Hoover, I would just put the full name for his first name, or if "J" is
entered, then just that, I suppose. Given name will be first name +
middle name(s). (I took most of this schema from a baseball database, so
maybe it's just something that worked better there.)
Sep 28 '06 #5
Dennis Lee Bieber wrote:
On Wed, 27 Sep 2006 18:41:54 GMT, John Salerno
<jo******@NOSPA Mgmail.comdecla imed the following in comp.lang.pytho n:
>You're right! I think that must have been leftover from when it wasn't
the last line in the query. Thanks!

You also, based upon the cut&paste, have a stray

"")

(or something similar in the last line)
I don't see this. The code works now, though. Maybe it was something
carried over by pasting.
Sep 28 '06 #6
Dennis Lee Bieber wrote:
On Thu, 28 Sep 2006 14:05:16 GMT, John Salerno
<jo******@NOSPA Mgmail.comdecla imed the following in comp.lang.pytho n:
>I don't see this. The code works now, though. Maybe it was something
carried over by pasting.

Here's a snippet from your original listing:
> nameFirst varchar(50) NOT NULL,
nameLast varchar(50) NOT NULL,
nameGiven varchar(255) DEFAULT NULL,
);
''')
That's correct, though, isn't it? Those quotes are the closing quotes of
the argument to executescript()
Sep 28 '06 #7
John Salerno wrote:
John Machin wrote:
John Salerno wrote:
CREATE TABLE Researchers (
researcherID varchar(9) PRIMARY KEY NOT NULL,
birthYear int(4) DEFAULT NULL,
birthMonth int(2) DEFAULT NULL,
birthDay int(2) DEFAULT NULL,
birthCountry varchar(50) DEFAULT NULL,
birthState char(2) DEFAULT NULL,
birthCity varchar(50) DEFAULT NULL,
nameFirst varchar(50) NOT NULL,
nameLast varchar(50) NOT NULL,
nameGiven varchar(255) DEFAULT NULL,
A bit OT, but one answer to the "can you make a living with just
Python" question is "Yup, tool of choice for rummaging in and fixing
data that's been mangled by users cramming it into dodgy data models"
:-)
[snip]
>
(2) It's not apparent how you would use the first, last, and given
names columns, especially with two of them being "not null". Consider
how you would store e.g.:
J Edgar Hoover
DJ Delorie
Sukarno
35
Maggie Cheung Man-Yuk
Molnar Janos
Fatimah binte Rahman
Zhang Manyu

Not sure I follow you on some of these examples. In the case of J Edgar
Hoover, I would just put the full name for his first name, or if "J" is
entered, then just that, I suppose. Given name will be first name +
middle name(s). (I took most of this schema from a baseball database, so
maybe it's just something that worked better there.)
You sure to be using "last name" to mean "surname" in the sense of
unchanging family name e.g. John and Mary Smith are the children of
Fred Smith, who is the son of Joe Smith.

You would address a letter to Mary as "Dear Ms Smith", and in follow-on
paragraphs in (say) a news article might refer to her using only the
surname e.g. "Smith also announced ...".

The problems are (1) there are cultures that don't have the concept of
a surname, and if they do, it may not be the "last name" (2) the name
may consist of only one word (giving you problems with "not null") or
not even be a word.

DJ Delorie -- his "given name" *is* DJ
Sukarno -- one word name
35 -- some jurisdictions allow name to include (or consist solely of)
digits
Maggie Cheung Man-Yuk -- surname is Cheung [Hong Kong romanisation]
Molnar Janos -- surname is Molnar
Fatimah binte Rahman -- no surname; daughter of person whose given name
is Rahman
Zhang Manyu -- surname is Zhang [pinyin romanisation]; same person as
Maggie Cheung Man-Yuk

It gets better:

Iceland: Jon Bjornsson and Hildur Bjornsdottir are the children of
Bjorn Eiriksson.

Portuguese: Jose Carlos Fernandes [mothers's family name] Rodrigues
[fathers's family name]; first step in shortening gives Jose Carlos
Rodrigues -- no drama here, but compare with Spanish: Jose Carlos
Fernandez [father's family name] Rodriguez [mother's family name],
shortened to Jose Carlos Fernandez.

[parts of] Somalia, Ethiopia: [using English given-name words for
clarity] Tom Dick Harry and Janet Dick Harry are the children of Dick
Harry Fred, who is the son of Harry Fred Joe.

Vietnamese: Full name e.g. Nguyen Thi Hoa Dung -- I have seen this
recorded as last name = Nguyen (that's the family name; doing well so
far), but first name = Thi. Thi means "Ms" or "female". The "first
name" is actually Dung. Given the popularity of Nguyen as a family name
(about 50% !!) , the recorded information has narrowed the choice to
about 25% of the Vietnamese population :-(

Cheers,
John

Sep 29 '06 #8
"John Machin" <sj******@lexic on.netwrites:
It gets better:

Iceland:...
Portuguese:...
[parts of] Somalia, Ethiopia:...
Vietnamese:...
You might add something about Arabic filionyms.
Sep 29 '06 #9
John Machin wrote:
John Salerno wrote:
>>John Machin wrote:
>>>John Salerno wrote:

CREATE TABLE Researchers (
researcherID varchar(9) PRIMARY KEY NOT NULL,
birthYear int(4) DEFAULT NULL,
birthMonth int(2) DEFAULT NULL,
birthDay int(2) DEFAULT NULL,
birthCountry varchar(50) DEFAULT NULL,
birthState char(2) DEFAULT NULL,
birthCity varchar(50) DEFAULT NULL,
nameFirst varchar(50) NOT NULL,
nameLast varchar(50) NOT NULL,
nameGiven varchar(255) DEFAULT NULL,

A bit OT, but one answer to the "can you make a living with just
Python" question is "Yup, tool of choice for rummaging in and fixing
data that's been mangled by users cramming it into dodgy data models"
:-)

[snip]
>>>(2) It's not apparent how you would use the first, last, and given
names columns, especially with two of them being "not null". Consider
how you would store e.g.:
J Edgar Hoover
DJ Delorie
Sukarno
35
Maggie Cheung Man-Yuk
Molnar Janos
Fatimah binte Rahman
Zhang Manyu

Not sure I follow you on some of these examples. In the case of J Edgar
Hoover, I would just put the full name for his first name, or if "J" is
entered, then just that, I suppose. Given name will be first name +
middle name(s). (I took most of this schema from a baseball database, so
maybe it's just something that worked better there.)


You sure to be using "last name" to mean "surname" in the sense of
unchanging family name e.g. John and Mary Smith are the children of
Fred Smith, who is the son of Joe Smith.

You would address a letter to Mary as "Dear Ms Smith", and in follow-on
paragraphs in (say) a news article might refer to her using only the
surname e.g. "Smith also announced ...".

The problems are (1) there are cultures that don't have the concept of
a surname, and if they do, it may not be the "last name" (2) the name
may consist of only one word (giving you problems with "not null") or
not even be a word.

DJ Delorie -- his "given name" *is* DJ
Sukarno -- one word name
35 -- some jurisdictions allow name to include (or consist solely of)
digits
Maggie Cheung Man-Yuk -- surname is Cheung [Hong Kong romanisation]
Molnar Janos -- surname is Molnar
Fatimah binte Rahman -- no surname; daughter of person whose given name
is Rahman
Zhang Manyu -- surname is Zhang [pinyin romanisation]; same person as
Maggie Cheung Man-Yuk

It gets better:

Iceland: Jon Bjornsson and Hildur Bjornsdottir are the children of
Bjorn Eiriksson.

Portuguese: Jose Carlos Fernandes [mothers's family name] Rodrigues
[fathers's family name]; first step in shortening gives Jose Carlos
Rodrigues -- no drama here, but compare with Spanish: Jose Carlos
Fernandez [father's family name] Rodriguez [mother's family name],
shortened to Jose Carlos Fernandez.

[parts of] Somalia, Ethiopia: [using English given-name words for
clarity] Tom Dick Harry and Janet Dick Harry are the children of Dick
Harry Fred, who is the son of Harry Fred Joe.

Vietnamese: Full name e.g. Nguyen Thi Hoa Dung -- I have seen this
recorded as last name = Nguyen (that's the family name; doing well so
far), but first name = Thi. Thi means "Ms" or "female". The "first
name" is actually Dung. Given the popularity of Nguyen as a family name
(about 50% !!) , the recorded information has narrowed the choice to
about 25% of the Vietnamese population :-(
While I don't dispute any of this erudite display of esoteric
nomenclature wisdom the fact remains that many (predominantly Western)
databases do tend to use first and last name (in America often with the
addition of a one- or two-character "middle initial" field).

So, having distilled your knowledge to its essence could you please give
me some prescriptive advice about what I *should* do? :-)

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Sep 29 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1969
by: John Machin | last post by:
Apologies in advance if this is a bit bloggy, but I'd like to get comments on whether I've lost the plot (or, more likely, failed to acquire it) before I start reporting bugs etc. From "What's new ...": """ # Create table c.execute('''create table stocks (date timestamp, trans varchar, symbol varchar, qty decimal, price decimal)''')
66
7045
by: mensanator | last post by:
Probably just me. I've only been using Access and SQL Server for 12 years, so I'm sure my opinions don't count for anything. I was, nevertheless, looking forward to Sqlite3. And now that gmpy has been upgraded, I can go ahead and install Python 2.5. So I open the manual to Section 13.13 where I find the first example of how to use Sqlite3:
2
4941
by: Josh | last post by:
Hi, I'm running into a problem when trying to create a view in my sqlite database in python. I think its a bug in the sqlite3 api that comes with python 2.5. This works as expected: conn = sqlite3.connect(':memory:') conn.execute("create table foo (a int,b int)") conn.execute('create view bar as select * from foo')
4
8918
by: Simon | last post by:
I installed the source code on unix for python 2.5.1. The install went mainly okay, except for some failures regarding: _ssl, _hashlib, _curses, _curses_panel. No errors regarding sqlite3. However, when I start python and do an import sqlite3 I get: /ptmp/bin/python Python 2.5.1 (r251:54863, May 29 2007, 05:19:30) on sunos5
2
2272
by: =?ISO-8859-1?Q?S=E9bastien_Ramage?= | last post by:
Hi ! I'm trying to build an client/server app based on Pyro and sqlite3. But I have a problem using sqlite3 on the server I got this error : sqlite3.ProgrammingError: ('SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 240 and this
12
17255
by: John | last post by:
Hi, I'm trying to connect to a SQLite3 database for days now but I'm stuck. PHP returns an error that I made a "call to undefined function sqlite_open(). In the php.ini the extension=php_pdo.dll and extension=php_sqlite.dll are set. What am I doing wrong??? Thank you in advance, John
3
2970
by: milan_sanremo | last post by:
I have sqlite installed, but when I try to import sqlite3 I receive: Python 2.5.1 (r251:54863, Nov 3 2007, 02:54:36) on sunos5 Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named sqlite3 Yet:
3
6783
by: Bev in TX | last post by:
I am a complete newbie at building Python. I am trying to build it under MS Windows Vista (64-bit AMD) with MS VS2005. I'm doing that because I need debug libraries, which I did not see in the standard distribution. I downloaded the source and found the MSVS8 solution/project files. However, when I tried to build it I got the following error: ....\python-2.5.2\modules\_sqlite\connection.h(33) : fatal error C1083: Cannot open include...
15
14738
by: Kurda Yon | last post by:
Hi, I try to "build" and "install" pysqlite? After I type "python setup.py build" I get a lot of error messages? The first error is "src/ connection.h:33:21: error: sqlite3.h: No such file or directory". So, I assume that the absence of the "sqlite3.h" is the origin of the problem. I found on the web, that this file should be either in "/usr/local/ include" or in "/usr/local/lib". I check this directories and I really
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.