Re: [Tutor] SQLite Django

2016-08-04 Thread Alan Gauld via Tutor
Forwarding to list. Please use REplyAll when responding to tutor messages. On 04/08/16 09:19, Trevor H wrote: > Hi Alan, > > Thank you for the reply. I'll try show the graphic as a website. Would > I have to make the data entries as a model in Django? > I'm not a Django expert so don;t know

Re: [Tutor] SQLite

2016-05-19 Thread Alan Gauld via Tutor
On 19/05/16 10:03, Crusier wrote: > c.execute('''CREATE TABLE stocks > (code text)''') > > # Insert a row of data > List = ['1', '2', '3', '4', '5', '6', '7', > '8', '9', '00010', '00011', '00012'] > > c.executemany('INSERT INTO stocks VALUES

Re: [Tutor] SQLite

2016-05-19 Thread Peter Otten
Crusier wrote: > Dear Alan, > > I have read your web page and try to test thing out on SQLite. > > Attached is my code: > > import sqlite3 > conn = sqlite3.connect('example1.db') > c = conn.cursor() > c.execute('drop table if exists stocks') > c.execute('''CREATE TABLE stocks >

[Tutor] SQLite

2016-05-19 Thread Crusier
Dear Alan, I have read your web page and try to test thing out on SQLite. Attached is my code: import sqlite3 conn = sqlite3.connect('example1.db') c = conn.cursor() c.execute('drop table if exists stocks') c.execute('''CREATE TABLE stocks (code text)''') # Insert a row of data

Re: [Tutor] sqlite

2016-05-18 Thread Terry Carroll
On Tue, 3 May 2016, Crusier wrote: I am just wondering if there is any good reference which I can learn how to program SQLITE using Python I can not find any book is correlated to Sqlite using Python. "The Definitive Guide to SQLite" is about SQLite, but includes a chapter on both PySQLite

Re: [Tutor] sqlite

2016-05-14 Thread Peter Otten
Alan Gauld via Tutor wrote: > On 13/05/16 21:25, Neil D. Cerutti wrote: > >> From your tutorial: >> >> query = '''INSERT INTO Address >> (First,Last,House,Street,District,Town,PostCode,Phone) >> Values ("%s","%s","%s","%s","%s","%s","%s","%s")''' %\ >>

Re: [Tutor] sqlite

2016-05-13 Thread Alan Gauld via Tutor
On 13/05/16 21:25, Neil D. Cerutti wrote: > From your tutorial: > > query = '''INSERT INTO Address > (First,Last,House,Street,District,Town,PostCode,Phone) > Values ("%s","%s","%s","%s","%s","%s","%s","%s")''' %\ > (first, last, house, street,

Re: [Tutor] sqlite

2016-05-13 Thread Neil D. Cerutti
On 5/3/2016 11:40 AM, Alan Gauld via Tutor wrote: On 03/05/16 10:09, Crusier wrote: I am just wondering if there is any good reference which I can learn how to program SQLITE using Python I can not find any book is correlated to Sqlite using Python. You can try my tutorial below.

Re: [Tutor] sqlite

2016-05-03 Thread Alan Gauld via Tutor
On 03/05/16 10:09, Crusier wrote: > I am just wondering if there is any good reference which I can learn how to > program SQLITE using Python > > I can not find any book is correlated to Sqlite using Python. You can try my tutorial below. http://www.alan-g.me.uk/tutor/tutdbms.htm If you want

[Tutor] sqlite

2016-05-03 Thread Crusier
Dear All, I am just wondering if there is any good reference which I can learn how to program SQLITE using Python I can not find any book is correlated to Sqlite using Python. Thank you Regards, Hank ___ Tutor maillist - Tutor@python.org To

[Tutor] SQLite, Python and SQL injection attacks

2015-08-14 Thread boB Stepp
I was just looking at the sqlite3 docs at https://docs.python.org/3/library/sqlite3.html?highlight=sqlite#module-sqlite3 and found the following cheery news: Usually your SQL operations will need to use values from Python variables. You shouldn’t assemble your query using Python’s string

Re: [Tutor] SQLite, Python and SQL injection attacks

2015-08-14 Thread Alan Gauld
On 14/08/15 19:40, boB Stepp wrote: Instead, use the DB-API’s parameter substitution. Put ? as a placeholder wherever you want to use a value, and then provide a tuple of values as the second argument to the cursor’s execute() method... This is not a Sqlite issue its true of any database. I

Re: [Tutor] SQLite, Python and SQL injection attacks

2015-08-14 Thread Emile van Sebille
On 8/14/2015 11:40 AM, boB Stepp wrote: I was just looking at the sqlite3 docs at https://docs.python.org/3/library/sqlite3.html?highlight=sqlite#module-sqlite3 and found the following cheery news: Usually your SQL operations will need to use values from Python variables. You shouldn’t

Re: [Tutor] SQLite, Python and SQL injection attacks

2015-08-14 Thread Cameron Simpson
On 14Aug2015 13:40, boB Stepp robertvst...@gmail.com wrote: I was just looking at the sqlite3 docs at https://docs.python.org/3/library/sqlite3.html?highlight=sqlite#module-sqlite3 and found the following cheery news: Usually your SQL operations will need to use values from Python variables.

[Tutor] sqlite question

2013-06-11 Thread Khalid Al-Ghamdi
Hi, I have a dictionary with keys as employee badges and values as their names. Both key and value are strings. I want to read the badges from a sql select and use that to look up the names in the dictionary. But since the result is a tuple, it doesnt' work. how can i overcome this? 1.

Re: [Tutor] sqlite question

2013-06-11 Thread Todd Matsumoto
I think you are missing the fetch call. The cursor only executed your query, but hasn't fetched any thing out. On Tue, Jun 11, 2013 at 12:20 PM, Khalid Al-Ghamdi emailkg...@gmail.comwrote: Hi, I have a dictionary with keys as employee badges and values as their names. Both key and value are

Re: [Tutor] sqlite search

2013-01-28 Thread Prasad, Ramit
Alan Gauld wrote: On 18/01/13 18:11, Roger wrote: At the moment this works to search for everything beginning with A sql = SELECT * FROM plants WHERE genus LIKE 'A%'; cursor.execute(sql); SQLlite supports a form of format string where you put in some magic charactrs then provide

Re: [Tutor] sqlite search

2013-01-27 Thread Alan Gauld
On 18/01/13 18:11, Roger wrote: At the moment this works to search for everything beginning with A sql = SELECT * FROM plants WHERE genus LIKE 'A%'; cursor.execute(sql); SQLlite supports a form of format string where you put in some magic charactrs then provide arguments which SQLLite will

Re: [Tutor] sqlite search

2013-01-27 Thread Oscar Benjamin
On 27 January 2013 18:21, Alan Gauld alan.ga...@btinternet.com wrote: On 18/01/13 18:11, Roger wrote: At the moment this works to search for everything beginning with A sql = SELECT * FROM plants WHERE genus LIKE 'A%'; cursor.execute(sql); SQLlite supports a form of format string where you

Re: [Tutor] sqlite search

2013-01-27 Thread ALAN GAULD
file:///home/alang/Documents/HomePage/tutor/tutdbms.htm You might have better luck using this link: http://www.alan-g.me.uk/tutor/tutdbms.htm Oops, thanks for spotting that!  I keep two copies of the site open in separate browser tabs and mistakenly used the local  file version when

[Tutor] sqlite search

2013-01-25 Thread Roger
Hello, I am very new to python. Wrote a small program to use on my android phone using pickle/shelve to access data. That worked fine but i realised it would be better to use sqlite as a database to more easily modify the data. I havent got a clue about sqlite, have a book but cant find the

[Tutor] sqlite search syntax

2013-01-18 Thread Roger Shaw
Hello, I am very new to python. Wrote a small program to use on my android phone using pickle/shelve to access data. That worked fine but i realised it would be better to use sqlite as a database to more easily modify the data. I havent got a clue about sqlite, have a book but cant find

Re: [Tutor] sqlite search syntax

2013-01-18 Thread Prasad, Ramit
Roger Shaw wrote: Hello, I am very new to python. Wrote a small program to use on my android phone using pickle/shelve to access data. That worked fine but i realised it would be better to use sqlite as a database to more easily modify the data. I havent got a clue about sqlite,

Re: [Tutor] SQLite database locked problem

2010-07-21 Thread Che M
Date: Tue, 20 Jul 2010 07:28:45 +0200 From: cwi...@compuscan.co.za To: pine...@hotmail.com CC: tutor@python.org Subject: Re: [Tutor] SQLite database locked problem On 20/07/2010 06:48, Che M wrote: I'm using an SQLite3 database (with Python 2.5) and every so often

[Tutor] SQLite database locked problem

2010-07-19 Thread Che M
I'm using an SQLite3 database (with Python 2.5) and every so often the application crashes or hangs because somewhere there is this error, or something like it: OperationalError: database is locked. This is probably because I am viewing and sometimes changing the database through SQLite

Re: [Tutor] SQLite database locked problem

2010-07-19 Thread Christian Witts
://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor SQLite

Re: [Tutor] SQLite error messages

2010-03-10 Thread Alan Harris-Reid
Benno Lang wrote: On 10 March 2010 11:37, Alan Harris-Reid aharrisr...@googlemail.com wrote: Hi there, I am using the sqlite3 module with Python 3.1, and have some code which goes something like as follows... import sqlite3 con = sqlite3.connect('MyDatabase.db') try: execresult =

Re: [Tutor] SQLite error messages

2010-03-10 Thread Alan Harris-Reid
Sander Sweers wrote: - Original message - I am using the sqlite3 module with Python 3.1, and have some code which goes something like as follows... import sqlite3 con = sqlite3.connect('MyDatabase.db') try: execresult = con.execute('INSERT INTO MyTable (field_name) VALUES

Re: [Tutor] SQLite error messages

2010-03-10 Thread Sander Sweers
On 10 March 2010 21:02, Alan Harris-Reid aharrisr...@googlemail.com wrote: Maybe I have misunderstood you, but I always thought that the 'finally' section was run even if the 'try' section is successful, in which case I would not want a rollback. I was thinking something like this. import

[Tutor] SQLite error messages

2010-03-09 Thread Alan Harris-Reid
Hi there, I am using the sqlite3 module with Python 3.1, and have some code which goes something like as follows... import sqlite3 con = sqlite3.connect('MyDatabase.db') try: execresult = con.execute('INSERT INTO MyTable (field_name) VALUES (MyValue)') con.commit() except:

Re: [Tutor] SQLite error messages

2010-03-09 Thread Benno Lang
On 10 March 2010 11:37, Alan Harris-Reid aharrisr...@googlemail.com wrote: Hi there, I am using the sqlite3 module with Python 3.1, and have some code which goes something like as follows... import sqlite3 con = sqlite3.connect('MyDatabase.db') try:   execresult = con.execute('INSERT

Re: [Tutor] SQLite error messages

2010-03-09 Thread Sander Sweers
- Original message - I am using the sqlite3 module with Python 3.1, and have some code which goes something like as follows... import sqlite3 con = sqlite3.connect('MyDatabase.db') try:         execresult = con.execute('INSERT INTO MyTable (field_name) VALUES (MyValue)')        

[Tutor] sqlite query problem

2010-01-29 Thread BOBÁK Szabolcs
Dear List Members, I need help in a mystic problem (I hope just for me) with python and sqlite3. Running enviroment: OS: Windows 2003 ENG 64bit, Windows XP HUN 32bit Python: ActiveState Python 2.6.4 32bit (It's a must because of PyWin extension in the future and I didn't have any issue with it

Re: [Tutor] sqlite query problem

2010-01-29 Thread Hugo Arts
2010/1/29 BOBÁK Szabolcs szabolcs.bo...@gmail.com: This also works, but this not: sql_command_stat = 'SELECT COUNT(lastmoddate) FROM '+sql_tablename_orig+'WHERE lastmoddate '+str(lastmod_date1) sql_cursor.execute(sql_command_stat) This was my original try, but tried various in various

Re: [Tutor] sqlite query problem

2010-01-29 Thread BOBÁK Szabolcs
Dear Hugo, Thank you for your fast help and the sharp eyes. I was almost hopeless. It is working now, but only with the first formula, and I also voted to the third one, so I will try a little bit more. Thank you very much! 2010. január 29. 17:53 Hugo Arts írta, hugo.yo...@gmail.com:

Re: [Tutor] SQLite database not update correctly

2009-11-09 Thread Che M
It's working fine now, but actually I didn't write exactly what you suggested. The commit method belongs to the connection, not to the cursor. Therefore, in my script it should be conn.commit(). Whoops, you're quite right. Went a little too fast there. :D Che

[Tutor] SQLite database not update correctly

2009-11-08 Thread Emmanuel Ruellan
Hi tutors, I've got a functions that should update an sqlite database, among other things. However the database doesn't get updated. When used in isolation, the update statement works fine. What am I doing wrong? Below is the function. The whole script can be found at

Re: [Tutor] SQLite database not update correctly

2009-11-08 Thread Che M
I've got a functions that should update an sqlite database, among other things. However the database doesn't get updated. When used in isolation, the update statement works fine. What am I doing wrong? Below is the function. The whole script can be found at

Re: [Tutor] SQLite database not update correctly

2009-11-08 Thread Emmanuel Ruellan
Thanks a lot, Che! It's working fine now. On Sun, Nov 8, 2009 at 9:13 PM, Che M pine...@hotmail.com wrote: I've got a functions that should update an sqlite database, among other things. However the database doesn't get updated. When used in isolation, the update statement works fine.

Re: [Tutor] SQLite database not update correctly

2009-11-08 Thread Emmanuel Ruellan
It's working fine now, but actually I didn't write exactly what you suggested. The commit method belongs to the connection, not to the cursor. Therefore, in my script it should be conn.commit(). On Sun, Nov 8, 2009 at 9:15 PM, Che M pine...@hotmail.com wrote: I've got a functions that should

Re: [Tutor] sqlite: don't understand a code snippet

2009-07-26 Thread David
Rich, thanks a lot -- that was the problem. David Rich Lovely wrote: 2009/7/25 David ld...@gmx.net: Dear tutors, I am trying to teach myself the way Python's works with databases. I decided to start with SQLite, and am looking at Summerfield's 'Programming in Python 3'. I got a code

[Tutor] sqlite: don't understand a code snippet

2009-07-25 Thread David
Dear tutors, I am trying to teach myself the way Python's works with databases. I decided to start with SQLite, and am looking at Summerfield's 'Programming in Python 3'. I got a code snippet that I don't fully understand (the comments are mine): def get_and_set_director(db, director): #

Re: [Tutor] sqlite: don't understand a code snippet

2009-07-25 Thread Rich Lovely
2009/7/25 David ld...@gmx.net: Dear tutors, I am trying to teach myself the way Python's works with databases. I decided to start with SQLite, and am looking at Summerfield's 'Programming in Python 3'. I got a code snippet that I don't fully understand (the comments are mine): def

Re: [Tutor] SQLite LIKE question

2008-04-12 Thread Dinesh B Vadhia
. The code is in my recent post (Subject: pysqlite and functions) with a new problem ie. the code works as-is but not within a def function. Dinesh .. Date: Fri, 11 Apr 2008 13:20:12 +0100 From: Tim Golden [EMAIL PROTECTED] Subject: Re: [Tutor

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Alan Gauld
Dinesh B Vadhia [EMAIL PROTECTED] wrote I'm using the LIKE operator to match a pattern against a string using this SELECT statement: for row in con.execute( SELECT column FROM table WHERE string LIKE '%q%' limit 25): With q=dog as a test example, I've tried '$q%', '%q%', '%q'

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Steve Willoughby
Simone wrote: In Python the symbol '%' in a string is a special char: you use it, for instance, to place a variable inside a string. For completeness, it's worth mentioning in passing that % is only special when you're doing string formatting. It's not otherwise special in strings. However,

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread linuxian iandsd
i forgot to mention that you need to try your sql commands out of your script before trying them inside, ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread linuxian iandsd
I m not sure this is your case but i believe you are missing the cur.fetchall() command which does fetch data from sql db i suggest you put a print statement for every data you use in your program that way you know whats empty whats not... here is example of MySQLdb process:

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Simone
Dinesh B Vadhia ha scritto: The second problem is that I'm using the LIKE operator to match a pattern against a string but am getting garbage results. For example, looking for the characters q='dog' in each string the SELECT statement is as follows: for row in con.execute(SELECT

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Dinesh B Vadhia
Okay, I've got this now: con = sqlite3.connect(:memory:) cur = con.cursor() cur.execute(CREATE TABLE db.table(col.a integer, col.b text)) con.executemany(INSERT INTO db.table(col.a, col.b) VALUES (?, ?), m) con.commit() for row in con.execute(SELECT col.a, col.b FROM db.table):

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Tim Golden
Dinesh B Vadhia wrote: Okay, I've got this now: con = sqlite3.connect(:memory:) cur = con.cursor() cur.execute(CREATE TABLE db.table(col.a integer, col.b text)) con.executemany(INSERT INTO db.table(col.a, col.b) VALUES (?, ?), m) con.commit() for row in con.execute(SELECT col.a, col.b

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Alan Gauld
Dinesh B Vadhia [EMAIL PROTECTED] wrote As Python/pysqlite stores the items in the db.table as unicode strings, I've also run the code with q=udog but get the same error. Same with putting the q as a tuple ie. (q) in the Select (q) is not a tuple, it is a variable surrounded by quotes.

[Tutor] SQLite LIKE question

2008-04-10 Thread Dinesh B Vadhia
I'm reading a text file into an in-memory pysqlite table. When I do a SELECT on the table, I get a 'u' in front of each returned row eg. (u'QB VII',) (u'Quackser Fortune Has a Cousin in the Bronx',) I've checked the data being INSERT'ed into the table and it has no 'u'. The second problem

Re: [Tutor] SQLite LIKE question

2008-04-10 Thread Alan Gauld
Dinesh B Vadhia [EMAIL PROTECTED] wrote I'm reading a text file into an in-memory pysqlite table. When I do a SELECT on the table, I get a 'u' in front of each returned row eg. (u'QB VII',) The u is not part of the data its Python telling you that the string is Unicode. The second

[Tutor] SQLite database creation bafflement

2007-08-20 Thread Che M
Hi, I am trying to simply create an SQLite database with Python. I find that when I try to create a new database file, *sometimes* it lets me do it, and sometimes it doesn't, and the only thing I am changing is the name of the database. I am baffled as to why some names appear to work and

Re: [Tutor] SQLite database creation bafflement

2007-08-20 Thread Alan Gauld
Che M [EMAIL PROTECTED] wrote don't. For example, this will create a brand new database on the desktop: conn = sqlite3.connect('C:\Documents and Settings\user\Desktop\mydatabase.db') But running *this*--only thing different is the database's name--gives the error, as shown: conn =

Re: [Tutor] SQLite database creation bafflement

2007-08-20 Thread Roel Schroeven
Che M schreef: Hi, I am trying to simply create an SQLite database with Python. I find that when I try to create a new database file, *sometimes* it lets me do it, and sometimes it doesn't, and the only thing I am changing is the name of the database. I am baffled as to why some names

Re: [Tutor] SQLite database creation bafflement

2007-08-20 Thread Che M
Thank you Alan and Roel for the insight, and Roel thank you for all the suggested ways to get around it. It's always nice when something goes from making no sense to making complete sense in a snap. Che _ Booking a flight? Know

Re: [Tutor] sqlite: does ? work in PRAGMA commands?

2007-08-06 Thread Terry Carroll
On Wed, 1 Aug 2007, Terry Carroll wrote: Does the ? approach not work with PRAGMA commands or something; or am I doing this wrong? Just a quick follow-up on this, in case anyone else cares. My conclusion is that it's not supported. Googling around I found this pysqlite bug report:

[Tutor] sqlite: does ? work in PRAGMA commands?

2007-08-02 Thread Terry Carroll
I'm using sqlite for the first time, so I'm not sure whether I'm trying to do something unsupported. or whether I'm trying to do something that's supported, but doing it wrong. I want to get information about a table in my database. The variable tablename holds the name of the table, and

Re: [Tutor] sqlite: does ? work in PRAGMA commands?

2007-08-02 Thread John Fouhy
I'm not sure about PRAGMA, but you can do introspection in sqlite by examining the table 'sqlite_master'. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] sqlite: does ? work in PRAGMA commands?

2007-08-02 Thread Terry Carroll
On Thu, 2 Aug 2007, John Fouhy wrote: I'm not sure about PRAGMA, but you can do introspection in sqlite by examining the table 'sqlite_master'. Thanks. That's how I get the table names, actually. But it doesn't give the column names. It does give the SQL used to create the table, so I

Re: [Tutor] sqlite: does ? work in PRAGMA commands?

2007-08-02 Thread Kent Johnson
Terry Carroll wrote: GET_TABLE_INFO_COMMAND = PRAGMA TABLE_INFO(?) pragma_cmd = GET_TABLE_INFO_COMMAND field_data = self.dbconn.execute(pragma_cmd, (tablename)) I get the error: sqlite3.OperationalError: near ?: syntax error Some of the variations included using tablename or

Re: [Tutor] sqlite: does ? work in PRAGMA commands?

2007-08-02 Thread John Fouhy
On 03/08/07, Terry Carroll [EMAIL PROTECTED] wrote: On Thu, 2 Aug 2007, John Fouhy wrote: I'm not sure about PRAGMA, but you can do introspection in sqlite by examining the table 'sqlite_master'. Thanks. That's how I get the table names, actually. But it doesn't give the column names.