Re: Silly/crazy problem with sqlite

2023-11-26 Thread Chris Green via Python-list
Stefan Ram wrote: > Chris Green writes: > >I have to say this seems very non-pythonesque to me, the 'obvious' > >default simply doesn't work right, and I really can't think of a case > >where the missing comma would make any sense at all. > > |6.15 Expression lists > ... > |an expression list co

Re: Silly/crazy problem with sqlite

2023-11-25 Thread Thomas Passin via Python-list
On 11/24/2023 4:49 PM, Rimu Atkinson via Python-list wrote: I really can't think of a case where the missing comma would make any sense at all. That is pretty tricky, yes. The comma means it's a tuple. Without the comma, it's just a string with parenthesis around it, which is a string.

Re: Silly/crazy problem with sqlite

2023-11-25 Thread Mats Wichmann via Python-list
On 11/24/23 14:10, Chris Green via Python-list wrote: Chris Green wrote: This is driving me crazy, I'm running this code:- OK, I've found what's wrong:- cr.execute(sql, ('%' + "2023-11" + '%')) should be:- cr.execute(sql, ('%' + x + '%',) ) I have to say this seems very

Re: Silly/crazy problem with sqlite

2023-11-25 Thread Sibylle Koczian via Python-list
Am 24.11.2023 um 22:49 schrieb Rimu Atkinson via Python-list: I really can't think of a case where the missing comma would make any sense at all. That is pretty tricky, yes. The comma means it's a tuple. Without the comma, it's just a string with parenthesis around it, which is a strin

Re: Silly/crazy problem with sqlite

2023-11-25 Thread Chris Green via Python-list
Chris Green wrote: > This is driving me crazy, I'm running this code:- OK, I've found what's wrong:- > cr.execute(sql, ('%' + "2023-11" + '%')) should be:- cr.execute(sql, ('%' + x + '%',) ) I have to say this seems very non-pythonesque to me, the 'obvious' default simply doesn'

Silly/crazy problem with sqlite

2023-11-25 Thread Chris Green via Python-list
This is driving me crazy, I'm running this code:- #!/usr/bin/env python3 # # # Show the electric fence history, default to last 24 hours # import sqlite3 import datetime import sys today = datetime.datetime.now()

Re: Silly/crazy problem with sqlite

2023-11-25 Thread Rimu Atkinson via Python-list
I really can't think of a case where the missing comma would make any sense at all. That is pretty tricky, yes. The comma means it's a tuple. Without the comma, it's just a string with parenthesis around it, which is a string. PyDev console: starting. Python 3.9.15 (main, Oct 28 2022

Re: Problem with sqlite

2008-03-31 Thread Gerhard Häring
aiwarrior wrote: > [...] > What i'm going to study is whether it's possible to evaluate if a > table already exists, and if so act accordingly. [...] You can use a statement like "CREATE TABLE IF NOT EXISTS tbl(col1, col2);". If you just want to check, you can query SQLite's schema metadata with

Re: Problem with sqlite

2008-03-30 Thread aiwarrior
Ok regarding Gerhard's comment of the try, except, pass, i came to understand that it's really bad code. And i should have referred that i put that there be cause i was getting: Traceback (most recent call last): File "C:\Python25\Projects\cp.py", line 48, in db = db() File "C:\Python25\P

Re: Problem with sqlite

2008-03-30 Thread aiwarrior
Ok regarding Gerhard's comment of the try, except, pass, i came to understand that it's really bad code. And i should have referred that i put that there be cause i was getting: Traceback (most recent call last): File "C:\Python25\Projects\cp.py", line 48, in db = db() File "C:\Python25\P

Re: Problem with sqlite

2008-03-29 Thread Carsten Haese
On Mar 29, 9:10 pm, Tim Roberts <[EMAIL PROTECTED]> wrote: > aiwarrior <[EMAIL PROTECTED]> wrote: > >def get_value( self, column ): > >self.cursor.execute( "SELECT %s FROM database" % column ) > >for n in self.cursor: > > print n > > I suspect you wanted "self.cursor

Re: Problem with sqlite

2008-03-29 Thread Tim Roberts
aiwarrior <[EMAIL PROTECTED]> wrote: > >I'm sorry about not saying showing the libraries. It was not on >purpose. You didn't make any comment on the rest of Gerhard's suggestion, nor does it appear that you took any action to correct them. You should get out of the habit of using extra parenthese

Re: Problem with sqlite

2008-03-29 Thread Tzury Bar Yochay
after executing insert do conection.commit() -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with sqlite

2008-03-29 Thread aiwarrior
On Mar 29, 6:41 pm, Gerhard Häring <[EMAIL PROTECTED]> wrote: > Ok, I'll review your code. > > aiwarrior wrote: > > class db: > > def __init__(self): #constructor > > conn = sqlite3.connect('./db.db') > > conn.isolation_level = None > > Autocommit mode is mostly for newbies who

Re: Problem with sqlite

2008-03-29 Thread Gerhard Häring
Ok, I'll review your code. aiwarrior wrote: > class db: > def __init__(self): #constructor > conn = sqlite3.connect('./db.db') > conn.isolation_level = None Autocommit mode is mostly for newbies who forget to call commit. Unfortunately, newbiews find enough other ways to shoot

Re: Problem with sqlite

2008-03-29 Thread Duncan Booth
aiwarrior <[EMAIL PROTECTED]> wrote: > When i execute this the database doesn't get filled with anything and > the program stays running in memory for ever. That's odd, when I execute the code you posted I just get "NameError: global name 'sqlite3' is not defined". You should always try to post

Problem with sqlite

2008-03-29 Thread aiwarrior
class db: def __init__(self): #constructor conn = sqlite3.connect('./db.db') conn.isolation_level = None self.cursor = conn.cursor() try: self.cursor.execute("CREATE TABLE database (album,filepath)" ) except: pass def add_entr