The SQLite engine is part of the OS. It doesn't support this extension.
The B4A SQL library simply passes the commands to the native engine.
I want to use Row Number feature that was released on that version
SELECT * FROM MyTable WHERE PartNumber = 1290375 AND Description = 'Top Plate'
SELECT *, rowid FROM MyTable WHERE PartNumber = 1290375 AND Description = 'Top Plate'
UPDATE MyTable SET Description = 'Bottom Plate' WHERE rowid = MyRowid
One option is to move to SQLCipher, which currently is based on SQLite version 3.25.2.Hi,
I want to ask.
I run query on SQLiteand it return 3.22.0.SQLite:SELECT sqlite_version()
I want to update the SQLite to 3.25.2 (at least, latest if possible) because I want to use Row Number feature that was released on that version.
Is there any way to update?
Hi @aericI think there are workarounds in SO or the Internet.
Hi @RichardNThe unique table field 'rowid'
Hi @MaharesUnless, you have a way to upgrade your Phone/Tablet to a newer one where the SQLite is 25
Hi @RB SmissaertOne option is to move to SQLCipher
True. The SQLite engine is part of the OS.I have my suspiscion that I need to update my phone OS.
To determine the last record added is easy, it will be the greatest rowid. To determine the last records modified in a group is rather more complicated and will involve you adding a date/time field and keeping it up to date every time an UPDATE or INSERT is executed.I want to get the last transaction from a group in a selected date.
SELECT MAX(rowid) FROM MyTable
SELECT * FROM MyTable [WHERE RecordModifiedDate BETWEEN '20230101224554' AND '20230102224554'] ORDER BY RecordModifiedDate
Alex...try this
B4X:Dim NewID as Int NewID=SQL1.ExecQuerySingleResult("SELECT last_insert_rowid() FROM tbl
Believe or not but I've seen the situation when MAX(rowid) and last_insert_rowid() had different results. MAX(rowid) returned 150 and you exepcted that the new record will be 151 but last_insert_rowid() returned 35 and one the next insert after it returned 151. Why? Because some records were deleted and 35 were among them.Alex...
The OP is looking for the last X records added or modified. Your last_insert_rowid() function only returns the same single value as MAX(rowid)
Hi @ErelTrue. The SQLite engine is part of the OS.
Hi @aeric , @Alex_197 , @RichardNI think you should explain better what you are trying to do
PurchaseDate ItemCode Price
1 June 2023 08:04:05 Apple 5000
1 June 2023 08:10:32 Apple 5100
1 June 2023 08:03:17 Orange 3400
1 June 2023 09:00:03 Orange 3300
SELECT * FROM Purchase P
WHERE PurchaseDate = (SELECT PurchaseDate FROM Purchase
WHERE strftime('%d-%m-%Y', PurchaseDate) = strftime('%d-%m-%Y', P.PurchaseDate) AND
ItemCode = P.ItemCode ORDER BY PurchaseDate DESC LIMIT 1)
I already solve this problem by using
SQLite:SELECT * FROM Purchase P WHERE PurchaseDate = (SELECT PurchaseDate FROM Purchase WHERE strftime('%d-%m-%Y', PurchaseDate) = strftime('%d-%m-%Y', P.PurchaseDate) AND ItemCode = P.ItemCode ORDER BY PurchaseDate DESC LIMIT 1)
PurchaseDate ItemCode Price
1 June 2023 08:04:05 Apple 5000
1 June 2023 08:10:32 Apple 5100
1 June 2023 08:03:17 Orange 3400
1 June 2023 09:00:03 Orange 3300
I want to get the latest price of each item on 1 June.
SELECT Price From Purchases WHERE PurchaseDate LIKE '20230601%' AND ItemCode = 'Apple' ORDER BY PurchaseDate DESC LIMIT 1
SELECT Price From Purchases WHERE PurchaseDate LIKE '20230601%' AND ItemCode = 'Orange' ORDER BY PurchaseDate DESC LIMIT 1
last_insert_rowid() only works after you inserted record(s) and are still in the same database connection. If you exit and run the database again, you will get 0.I tried a couple of different databases and I can't seem to get last_insert_rowid() to return anything but zero. ????
Thanks @Mahares that's a new one on me.... you learn something every day It also makes last_insert_rowid() useless in the solution that @janitra is seeking as it will revert to zero on every database discconnect.last_insert_rowid() only works after you inserted record(s) and are still in the same database connection. If you exit and run the database again, you will get 0.
I agree entirely. Many of the misunderstandings relating to B4X arise from new users writing code that is unreadable. If they have got this deep into SQLite functions, they probably already understand the basics of wrapping SQL commands in B4X code...... so I keep it as simple as possible.I also highly recommend using a parameterized query especially when you are working with sensitive data that involve dates.
You are still not providing good information for members to help you. The date format you supplied in your example table does not work the way you have it with strFtime function. Also, your query is too complex and above all not correct at all. I am still puzzled by how you say you solved it with the code you entered.Lets say I have table with 3 column with 4 rows of data.
B4X:PurchaseDate ItemCode Price 1 June 2023 08:04:05 Apple 5000 1 June 2023 08:10:32 Apple 5100 1 June 2023 08:03:17 Orange 3400 1 June 2023 09:00:03 Orange 3300
I believe the MAX of rowid for the given date should do it.Hi @aeric
Thanks for your continuous support.
Yea, I'll try to do some workaround on monday.
Hi @RichardN
I want to get the last transaction from a group in a selected date.
That's why I think it will be convinient if I can use Row_Number() function on SQLite.
And I read that it come with SQLite v. 3.25 and I read more and stumble on a B4J post to update a SQLite version, and I thought maybe.... we can do same thing in B4A.
After some searching, I cannot found a thread and decide to ask.
And apparently we cannot do it in B4A.
So I'll try to do some work around on Monday as aeric suggested.
Hi @Mahares
I see.
I have my suspiscion that I need to update my phone OS.
Because I already change my target SDK to 30 and update SDK Platforms to 30 to no avail.
I'll test this in the near future.
Thanks a lot.
Hi @RB Smissaert
I see.
This is new thing for me.
I'll try to research it.
Thank you for your knowledge.