M Malky Active Member Licensed User Longtime User Feb 19, 2013 #1 I seem to have this problem with only one table (so far). If I want to update tables I use the DELETE * from tablename which has always worked before. (Sometimes at the wrong time, but we learn!) I get an error with one table for some reason? Has anyone experienced this? I pulled the table onto the computer and tried the same thing with sqllite and it locks up? I did try DELETE & from 'tablename' and DELETE * from tablename where 1 and many variations, but nope! Cheers. Malky
I seem to have this problem with only one table (so far). If I want to update tables I use the DELETE * from tablename which has always worked before. (Sometimes at the wrong time, but we learn!) I get an error with one table for some reason? Has anyone experienced this? I pulled the table onto the computer and tried the same thing with sqllite and it locks up? I did try DELETE & from 'tablename' and DELETE * from tablename where 1 and many variations, but nope! Cheers. Malky
E edgar_ortiz Active Member Licensed User Longtime User Feb 19, 2013 #2 The correct statement is: delete from table_name Regards Edgar Upvote 0
A abner69 Member Licensed User Longtime User Feb 19, 2013 #3 one additional note, if you are deleting a lot of records (or just want to shrink the size of your database, execute this sqlite command: vacuum; ...Pablo Upvote 0
one additional note, if you are deleting a lot of records (or just want to shrink the size of your database, execute this sqlite command: vacuum; ...Pablo
M Mahares Expert Licensed User Longtime User Feb 19, 2013 #4 I had a SQLite database with one table having 20000 records with a size of 3.6 MB. I deleted all 20000 records. The size dropped to 290 KB without issuing any VACUUM command. When is it necessary to vacuum and when is it not? I have yet to see a firm answer to this. Upvote 0
I had a SQLite database with one table having 20000 records with a size of 3.6 MB. I deleted all 20000 records. The size dropped to 290 KB without issuing any VACUUM command. When is it necessary to vacuum and when is it not? I have yet to see a firm answer to this.
eps Expert Licensed User Longtime User Feb 20, 2013 #5 You may well find that it depends on the version of SQLLite that's implemented. It's probably something that was an issue in the earlier versions, but they've now automated it. Upvote 0
You may well find that it depends on the version of SQLLite that's implemented. It's probably something that was an issue in the earlier versions, but they've now automated it.
M Malky Active Member Licensed User Longtime User Feb 23, 2013 #6 I tried the delete method previously mentioned with no success. I resorted back to DROP table_name and then recreating it with no success? I have a scrollview with a list of items. When I need to update this from my own server, I use the following code. Code: Copy Sub CreateMenuTable Log("menu table created") If Started = 0 Then SQL1.ExecNonQuery("DROP TABLE IF EXISTS menus") SQL1.ExecNonQuery("CREATE TABLE menus (id INTEGER PRIMARY KEY, en TEXT, ru TEXT, bg TEXT, gr TEXT, icon TEXT)") End If End Sub Although I change the text live on my server and do an update, the scrollview still displays the same data minus any changes? I checked the database and it has the amended text, but after recreating the scrollview I still see the previous text even after the new query to the database? Malky Upvote 0
I tried the delete method previously mentioned with no success. I resorted back to DROP table_name and then recreating it with no success? I have a scrollview with a list of items. When I need to update this from my own server, I use the following code. Code: Copy Sub CreateMenuTable Log("menu table created") If Started = 0 Then SQL1.ExecNonQuery("DROP TABLE IF EXISTS menus") SQL1.ExecNonQuery("CREATE TABLE menus (id INTEGER PRIMARY KEY, en TEXT, ru TEXT, bg TEXT, gr TEXT, icon TEXT)") End If End Sub Although I change the text live on my server and do an update, the scrollview still displays the same data minus any changes? I checked the database and it has the amended text, but after recreating the scrollview I still see the previous text even after the new query to the database? Malky
M Malky Active Member Licensed User Longtime User Feb 26, 2013 #7 Ok, I still have a problem with this after many hours of trying stuff and I can only assume that the primary key value is the problem after dropping the table????? I run this code to update the records (and remove any that need it) when I try to recreate the table from scratch:- Code: Copy SQL1.ExecNonQuery("DROP TABLE IF EXISTS diction") SQL1.ExecNonQuery("CREATE TABLE diction (id INTEGER PRIMARY KEY, en TEXT, bg TEXT, ru TEXT, gr TEXT)") I get a primary key error ever time. If I remove the 'PRIMARY' part of the query then I end up with duplicates? Any ideas welcome. Cheers, Malky Upvote 0
Ok, I still have a problem with this after many hours of trying stuff and I can only assume that the primary key value is the problem after dropping the table????? I run this code to update the records (and remove any that need it) when I try to recreate the table from scratch:- Code: Copy SQL1.ExecNonQuery("DROP TABLE IF EXISTS diction") SQL1.ExecNonQuery("CREATE TABLE diction (id INTEGER PRIMARY KEY, en TEXT, bg TEXT, ru TEXT, gr TEXT)") I get a primary key error ever time. If I remove the 'PRIMARY' part of the query then I end up with duplicates? Any ideas welcome. Cheers, Malky
S sorex Expert Licensed User Longtime User Feb 26, 2013 #8 not sure if sqlite supports it but the right command to empty (read trash) a table is the truncate command. never used sqlite so the delete might call a truncate command aswell if you don't supply record id's or other "checks" Upvote 0
not sure if sqlite supports it but the right command to empty (read trash) a table is the truncate command. never used sqlite so the delete might call a truncate command aswell if you don't supply record id's or other "checks"
M Malky Active Member Licensed User Longtime User Feb 26, 2013 #9 Thanks but I've tried various suggested sql lite sql commands but b4a doesn't like them. Tried the delete option again, tried many other commands and all my tables get duplicate records if I remove the PRIMARY KEY part. If I leave the PRIMARY KEY, I get the duplicate key errors again. From my searching the internet etc, the DELETE command should reset the auto increment value. Really frustrating!!!!! Malky Upvote 0
Thanks but I've tried various suggested sql lite sql commands but b4a doesn't like them. Tried the delete option again, tried many other commands and all my tables get duplicate records if I remove the PRIMARY KEY part. If I leave the PRIMARY KEY, I get the duplicate key errors again. From my searching the internet etc, the DELETE command should reset the auto increment value. Really frustrating!!!!! Malky
Erel B4X founder Staff member Licensed User Longtime User Feb 27, 2013 #10 Thanks but I've tried various suggested sql lite sql commands but b4a doesn't like them. Click to expand... Basic4android doesn't do anything with the query or command. It just passes it to the native SQLite engine. Upvote 0
Thanks but I've tried various suggested sql lite sql commands but b4a doesn't like them. Click to expand... Basic4android doesn't do anything with the query or command. It just passes it to the native SQLite engine.
S sorex Expert Licensed User Longtime User Feb 27, 2013 #11 Malky said: Although I change the text live on my server and do an update, the scrollview still displays the same data minus any changes? I checked the database and it has the amended text, but after recreating the scrollview I still see the previous text even after the new query to the database? Click to expand... so your feed your local sqlite database with data coming from a webserver? how do you pull it in? smells more like it is reading in a cached copy, that also has been an issue with Flash. The trick to use there is using an url like this url="http://www.mysite.com/getdata.php?r=" & r where r is a random value or time ticks value used to prevent reading in cached info. if it then still doesn't update right it's something on the sqlite side, can you dump the json output to the sd to see it it pulls it in right? Edit: just had a look at one of my apps that also pulled in data from a webserver and the command req.InitializeGet works fine without the additional random trick, not sure if you use that aswell? Last edited: Feb 27, 2013 Upvote 0
Malky said: Although I change the text live on my server and do an update, the scrollview still displays the same data minus any changes? I checked the database and it has the amended text, but after recreating the scrollview I still see the previous text even after the new query to the database? Click to expand... so your feed your local sqlite database with data coming from a webserver? how do you pull it in? smells more like it is reading in a cached copy, that also has been an issue with Flash. The trick to use there is using an url like this url="http://www.mysite.com/getdata.php?r=" & r where r is a random value or time ticks value used to prevent reading in cached info. if it then still doesn't update right it's something on the sqlite side, can you dump the json output to the sd to see it it pulls it in right? Edit: just had a look at one of my apps that also pulled in data from a webserver and the command req.InitializeGet works fine without the additional random trick, not sure if you use that aswell?
M Malky Active Member Licensed User Longtime User Feb 27, 2013 #12 I'm passing the arguments as they should be, it's just nothing is happening? I've tried to DROP the table and recreate it, no result. I've tried DELETE FROM tablename, no result. I've tried DELETE FROM tablename WHERE id > -1, no result? The only way I can add the data is if I remove the PRIMARY key on the id column, but then I get duplicate rows. The Scrollviews are cleared and recreated, plus I have pulled the DB from the phone and opened it and there are duplicate rows, so it's not the lists? This is driving me crazy as I've been at this for night's on end now. Malky Upvote 0
I'm passing the arguments as they should be, it's just nothing is happening? I've tried to DROP the table and recreate it, no result. I've tried DELETE FROM tablename, no result. I've tried DELETE FROM tablename WHERE id > -1, no result? The only way I can add the data is if I remove the PRIMARY key on the id column, but then I get duplicate rows. The Scrollviews are cleared and recreated, plus I have pulled the DB from the phone and opened it and there are duplicate rows, so it's not the lists? This is driving me crazy as I've been at this for night's on end now. Malky
S sorex Expert Licensed User Longtime User Feb 27, 2013 #13 that's strange indeed. there are other posts about issues but those were errors due to file locks or something Upvote 0
that's strange indeed. there are other posts about issues but those were errors due to file locks or something
M Malky Active Member Licensed User Longtime User Feb 27, 2013 #14 The only possible option I can see is to get a list of existing 'id's for each table and updating where a row exists, or inserting if it doesn't, but it seems a lot of code to get round something that should be simple and apparently works? Malky Upvote 0
The only possible option I can see is to get a list of existing 'id's for each table and updating where a row exists, or inserting if it doesn't, but it seems a lot of code to get round something that should be simple and apparently works? Malky
E edgar_ortiz Active Member Licensed User Longtime User Feb 27, 2013 #15 Malky, Post your project. It's help to find the solution. Regards Edgar Upvote 0
S sorex Expert Licensed User Longtime User Feb 28, 2013 #16 Is this only to feed a listbox? Why not just read it in from the website and copy the http response to the app folder just in case there is no internet connection? you won't notice a difference fetching it from a local database or looping throught the offline copy or the http response. and you can keep all your different listbox data in 1 response/offline_copy to make things easier. Upvote 0
Is this only to feed a listbox? Why not just read it in from the website and copy the http response to the app folder just in case there is no internet connection? you won't notice a difference fetching it from a local database or looping throught the offline copy or the http response. and you can keep all your different listbox data in 1 response/offline_copy to make things easier.
M Malky Active Member Licensed User Longtime User Feb 28, 2013 #17 Hi as requested, I'm adding the code in case someone can help? Please don't use any of the contact options as they are live!! Basically, I start the app, select the language and when presented with the menu, I select 'Update' to emulate someone trying to update for any new data each week or month etc. It's when I try the update that I get the problem with duplicate scrollview items. The main reason for doing it this way is to allow it to be used offline because of the area coverage here. Cheers, Malky Attachments homer.zip homer.zip 64.1 KB · Views: 481 Upvote 0
Hi as requested, I'm adding the code in case someone can help? Please don't use any of the contact options as they are live!! Basically, I start the app, select the language and when presented with the menu, I select 'Update' to emulate someone trying to update for any new data each week or month etc. It's when I try the update that I get the problem with duplicate scrollview items. The main reason for doing it this way is to allow it to be used offline because of the area coverage here. Cheers, Malky
S sorex Expert Licensed User Longtime User Feb 28, 2013 #18 It's when I try the update that I get the problem with duplicate scrollview items. Click to expand... did you forget to clear the scrollview/listview content before adding the others? Upvote 0
It's when I try the update that I get the problem with duplicate scrollview items. Click to expand... did you forget to clear the scrollview/listview content before adding the others?
M Malky Active Member Licensed User Longtime User Feb 28, 2013 #19 I've never had to before? Some of the scrollviews are repopulated each time a previous srcollview (scv) selection changes. i.e. if I select item 1 from scv, then the next one contains only relations of item 1. If I go back and select item 4, then the list appears with only items related to item 4. At the end of the day that wouldn't matter anyway. After checking the db after an update attempt, it has duplicate entries! Malky Upvote 0
I've never had to before? Some of the scrollviews are repopulated each time a previous srcollview (scv) selection changes. i.e. if I select item 1 from scv, then the next one contains only relations of item 1. If I go back and select item 4, then the list appears with only items related to item 4. At the end of the day that wouldn't matter anyway. After checking the db after an update attempt, it has duplicate entries! Malky
S sorex Expert Licensed User Longtime User Feb 28, 2013 #20 I'm missing some libs so I can't test it untill I have those. Can you give some hints on this? Edit: what happends if you put Started=0 in Sub Update right under the Log("Update") Last edited: Feb 28, 2013 Upvote 0
I'm missing some libs so I can't test it untill I have those. Can you give some hints on this? Edit: what happends if you put Started=0 in Sub Update right under the Log("Update")