Sibylle Koczian wrote: > trying out a dTextBox with decimal values (which works without problems, > thank > you for the quick answers!) I hit a new snag:
Glad that part is working! > SQLite database, one table, only the three fields mentioned in the UserSQL. > The primary key in this case is of type CHAR(3) and is filled in manually in > the application. No autoincrement, no setting by trigger. See AutoPopulatePK property. In your case, I believe it needs to be set to False. http://paul.dabodev.com/doc/api/dabodoc/dabo.biz.dBizobj.dBizobj.html#Properties_AutoPopulatePK > Application with > three dTextBox instances for these three fields and buttons for navigating, > New, Save, Cancel, Exit. > > 1. self.DefaultValues = None: > > class BizNum(dabo.biz.dBizobj): > def initProperties(self): > self.DataSource = "numtest" > self.KeyField = "idn" > self.UserSQL = """SELECT idn, amount, remark FROM numtest""" > self.DefaultValues = None > self.DataStructure = (("idn", "C", True, "numtest", "idn"), > ("amount", "N", False, "numtest", "amount"), > ("remark", "C", False, "numtest", "remark")) > > Button "New" fills in the idn field with "-1-", the two other fields > with "<None>". I overwrite the "-1-" with a unique new value for the PK and > enter a number into the "amount" field. Then I press "Save" and get this: The whole value is '-1-dabotmp', which indicates to Dabo that this new record still needs its real pk filled in, which will happen after the save(): dabo will find out the pk value from the database backend and fill it in for local use. I think you are confusing Dabo by telling it that AutoPopulatePK is True (because that's the default) but then giving the pk value manually. > "Save Failed: > > no such column: dabo-tmpKeyField > SQL: update "numtest" set "idn" = 'AC1', "amount" = 34.50, "remark" = > NULL, "dabo-tmpKeyField" = NULL where "idn"='-1-dabotmp' " > > 2. Nothing set for self.DefaultValues: > > Button "New" fills the idn field with "-1-" as before, the "amount" field > with "0.00", the "remark" field stays empty. I enter values, press "Save". No > error message, "Changes to all records saved" in the status line. I navigate > in the data, the last record is the newly entered one. I close my application > and start the sqlite command line client: no trace of the new record. > > 3. self.DefaultValues = {"idn": "ZZZ", "remark": None}: > > Now the idn field of a new record is filled with "ZZZ" If I change that value > (which would be the normal procedure), the result is exactly the same as > before (No. 2). If I let it unchanged (one record with primary key ZZZ would > be possible), I get: > > "Save Failed: > > numtest.idn may not be NULL > SQL: insert into "numtest" ("amount", "remark") values (8999.33, NULL) " > > 4. self.AutoPopulatePK = false: > > The idn field of a new record is now empty, but still "Changes to all records > saved" and no new record in the database when I view it with the sqlite > command line client (or if I close and restart my dabo application). > > I can't find any way to get new records into the database. This seems to be a > problem with manually entered primary keys, it doesn't happen with > autoincrement PK fields. Will try this next with a Firebird database, because > I really need this with one of my Firebird databases. > > What can I do? Sorry, I missed at first reading that you are setting AutoPopulatePK to False ('false' was just a typo, right?). I can tell you that my sqlite-based application uses app-generated pk's and I don't recall having such trouble. Here's the relevant code from my base bizobj: 1 # -*- coding: utf-8 -*- 2 3 from dabo.lib import getRandomUUID 4 import dabo.lib.datanav2 as datanav 5 6 class Base(datanav.Bizobj): 7 8 def afterInit(self): 9 self.super() 10 self.setBaseSQL() 11 12 13 def initProperties(self): 14 self.AutoQuoteNames = False 15 self.AutoPopulatePK = False 16 self.DefaultValues["id"] = getRandomUUID 17 self.SaveNewUnchanged = True You can see that my default value for the pk field is the dabo.lib.getRandomUUID function, but you could set it to any function that returns a value. The SaveNewUnchanged property could come into play when everything is filled with default values: If you do a new() and a save() without having changed anything different from what was set with DefaultValues, the record won't be saved even though there wasn't any indication that it didn't get saved. Therefore, I set this to True in my base bizobj subclass. Paul _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users Searchable Archives: http://leafe.com/archives/search/dabo-users This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]
