Re: Cursor Not Passed Properly Inter-Module
Adrian Klaver <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
On Tuesday 28 November 2006 02:50 pm, Rich Shepard wrote:
> While I thought I had this written correctly, testing proves me
> incorrect.
>
> One module, named 'dbMethods.py,' has the class DBTools with several
> methods. The initial lines are:
>
> class DBtools:
> appData = config.appData
>
> def CreateDB(self, dbFileName):
> con = None
> cur = None
>
> if not con:
> con = sqlite3.connect(self.appData.dbFileName)
> cur = con.cursor()
>
> """ Overall model information """
> cur.execute("CREATE TABLE model (model_name TEXT NOT NULL \
> PRIMARY KEY, model_desc TEXT, model_type TEXT, \
> keName TEXT, agent INTEGER);")
>
> This was modeled on the usage guide.
>
> Another module, named 'modelPage.py,' starts with
> from dbMethods import DBtools
> then calls the CreateDB() method as:
> dba = DBtools().CreateDB(self.appData.dbFileName)
>
> The error message presented by pthon is:
>
> Traceback (most recent call last):
> File "/data1/eikos/modelPage.py", line 202, in OnSaveMod
> dba = DBtools.cur.execute("insert or replace into model (model_name,
> model_desc, model_type, \
> AttributeError: class DBtools has no attribute 'cur'
>
> This may be a mis-used or missing 'self', but when I insert print
> statements in CreateDB() after the connection and cursor are defined, they
> show up as existing.
>
> A clue stick gently applied would be very helpful.
>
> Rich
I am somewhat confused. The execute statement that is failing is different
then the one you are showing i.e. you show a CREATE TABLE statement and the
statement that fails is an INSERT statement. Does the CREATE TABLE succeed ?
What happens in OnSavMod? (The part of the code that seems to be failing)
--
Adrian Klaver
[email protected]