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 04:16 pm, Rich Shepard wrote:
> On Tue, 28 Nov 2006, Adrian Klaver wrote:
> > I am somewhat confused.
>
> My apologies, Adrian.
>
> > 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)
>
> Let me try to clarify. Yes, the table is created, and the code is
> failing after I enter more data and click the "Save" button. Here's the
> method in the calling module:
>
> def OnSaveMod(self, event):
> self.modName = self.tcName.GetValue()
> self.modDesc = self.tcDesc.GetValue()
> self.modType = self.rb.GetString(self.rb.GetSelection())
> self.knowlEng = self.keName.GetValue()
> self.method = self.agent.GetSelection()
> DBtools.cur.execute("insert or replace into model (model_name,
> model_desc, \ model_type, keName, agent) values \
> (self.modnName, self.modDesc, self.modType, \
> self.knowlEng, self.method)")
> DBtools().SaveDB(self.appData.dbFileName)
>
> and the error message is:
>
> Traceback (most recent call last):
> File "/data1/eikos/modelPage.py", line 202, in OnSaveMod
> self.dba = DBtools.cur.execute("insert or replace into model
> (model_name, model_desc, model_type, \
> AttributeError: class DBtools has no attribute 'cur'
>
> Class DBTools() begins with:
>
> class DBtools:
> appData = config.appData
>
> def CreateDB(self, dbFileName):
> self.con = sqlite3.connect(self.appData.dbFileName)
> self.cur = self.con.cursor()
>
> The application sequence is this: I click the "New" button, and
> DBtools.CreateDB is called with the name of the sqlite3 database file (in
> the modName variable, above). So, the database connection and cursor are
> established here.
>
> Next, I enter some data in the widgets where they are assigned to
> modDesc and the rest. Then I click the "Save" button which calls
> OnSaveMod() that then calls the cursor to execute the insert with the new
> data.
>
> Does this make it clearer?
>
> Rich
I think I see what is happening. In your first post dba creates an instance of
DBtools().CreateDB(). This has a cursor associated with via the if statement.
The cursor executes the CREATE TABLE statement. In the OnSaveMod there is no
creation of a DBtools instance. Calling DBTools.cur.execute fails because at
the top level of the class cur=None. With what you have shown cur is only
available through the CreateDB function.
--
Adrian Klaver
[email protected]