Re: Cursor Not Passed Properly Inter-Module

Rich Shepard <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
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

-- 
Richard B. Shepard, Ph.D.               |    The Environmental Permitting
Applied Ecosystem Services, Inc.(TM)    |            Accelerator
<http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax: 503-667-8863
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.