RealSQLDatabase <-> SQLiteDatabase Update Problem

Hi,

hab mal zum Test umgestellt auf SQLiteDatabase und damit meine alten Datenbanken die mit RealSQLDatabase erstellt wurden getestet.
Lesen klappt, RecordSet einfügen klappt auch, nur Update bzw. löschen tut sich gar nichts.

Hab natürlich in der Lang. Ref. gelesen, aber mir erschließt sich nicht warum das nicht klappt.

Ich muss dazu sagen, ich habe keinen selbst definierten PrimaryKey in meinen Tabellen, sondern benutze bisher rowid und meine_rowid int64, die ich selbst verwalte.

Hat da jemand eine Idee?

[quote=9723:@Stefan Sicurella]Hi,

hab mal zum Test umgestellt auf SQLiteDatabase und damit meine alten Datenbanken die mit RealSQLDatabase erstellt wurden getestet.
Lesen klappt, RecordSet einfügen klappt auch, nur Update bzw. löschen tut sich gar nichts.

Hab natürlich in der Lang. Ref. gelesen, aber mir erschließt sich nicht warum das nicht klappt.

Ich muss dazu sagen, ich habe keinen selbst definierten PrimaryKey in meinen Tabellen, sondern benutze bisher rowid und meine_rowid int64, die ich selbst verwalte.

Hat da jemand eine Idee?[/quote]

Apologies for replying in English, I only know enough German to say ‘good day’ and ‘no’.

RecordSet.Update and RecordSet.Delete need to know the rowid or primary key in order to know what record to update. REALSQLDatabase’s SQLSelect actually inserted the rowid column into all queries to make this work. Unfortunately this inserting breaks complicated queries.

When designing SQLiteDatabase, we chose to avoid this automatic insertion. This means that you need to start inserting rowid yourself into your selects. Alternatively you can insert meine_rowid but you would have to mark it as being a PrimaryKey in SQLite. Otherwise RecordSet won’t know that it is a primary key and will refuse to do Update/Delete (like you’ve already ran into).

Not to say it shouldn’t be documented somewhere in the language reference, but there was a release note about it:

Klicken Sie hier für eine grobe Übersetzung.

Danke, Herr Araujo.

Ja, das steht auch in der Language ref. aber da steht auch:

If you don’t explicitly define your own INTEGER PRIMARY KEY column, you won’t get the ‘rowid’ column unless you specifically include it in the list of columns to include in your query:
SELECT rowid, * FROM TableName

Mein Code sieht so aus:
r=dbfakt.sqlselect(“select rowid AS rowid, * from adressen where meine_rowid=’”+a1+"’")
r.deleterecord
r.update
if dbfakt.ErrorCode>0 then msgbox dbfakt.ErrorMessage+"-"+str(dbfakt.ErrorCode)

oder:

        r=dbfakt.sqlselect("select rowid, * from adressen where meine_rowid='"+a1+"'")
        r.deleterecord
        r.update
        if dbfakt.ErrorCode>0 then global_msgbox dbfakt.ErrorMessage+"-"+str(dbfakt.ErrorCode)

eines von beiden müsste doch kalppen?

ROWID is “special”
IF you don’t define an integer primary key the sqlite adds it to your table
If you DO define an integer primary key then sqlite treats “ROWID” as an alias to the column you defined
ROWID ALWAYS exists

so you can do
r=dbfakt.sqlselect(“select rowid from adressen where meine_rowid=’”+a1+"’")
you really dont need all the rest of the data - just the rowid

I’m not sure what you expect
r.deleterecord
r.update
to do for you though ?

Ok, i did NOT defined a primary key in my databases. I have a column my_rowid manually updated by me, don’t know why but now all my databases have no primary key but a my_rowid.

Now i can save a new databaserecord, i can read a recordset, but i can’t update or delete it.

my code to delete a recordset with Realsqldatabase is:
r=dbfakt.sqlselect(“select rowid, * from adressen where my_rowid=’”+a1+"’")
r.deleterecord
r.update

how to do the same with sqlitedatabase and the same database, i tried the following with no success (error message: RecordSet is not editable because no primary key exists)
r=dbfakt.sqlselect(“select rowid, * from adressen where my_rowid=’”+a1+"’")
r=dbfakt.sqlselect(“select my_rowid AS rowid, * from adressen where my_rowid=’”+a1+"’")
r=dbfakt.sqlselect(“select my_rowid, * from adressen where my_rowid=’”+a1+"’")

the question is now, can i use the same database with NO Primary key and how?