SQLite/Notifier/Button not working the first time

Maybe , here :
I think it’s these blocks…

Apologies for the late reply but due to hour difference it is pretty difficult to keep up.

To @Taifun - Yes @Rogerio_Rios is correct, “above” refers to the SQL query inside the notifier. I only placed that notifier for troubleshooting to demonstrate to you guys how I know for certain that the db works and can be “pinged”. I used the notifier instead of a Do it. The notifier returns the number ‘1’ UNLESS it returns the text ‘1’ and there is no correlation between number/text ‘1’ in the first run. The SQLite table however describes this as ‘uselect INTEGER NOT NULL’ hence I’m expecting a number but am I treating this as a text? In theory either number or text should be treated in the same manner.

I will try to change the component number 1 to text 1 and let you know in a few hours. - NEW EDIT - I tried that but no change the problem persists.

Also I’m trying this on Android 7 and 10, as stated in the initial message according to the rules of the site/community, via two different Xiaomi Red Notes, I know, not the best of phones but if it works in these I know it will work on other phones due to past experience.

BTW I placed all notifiers with SQL queries only for troubleshooting purposes the actual app does not have these notifiers. I prefer the notifier over the Do it when pinging a db, I don’t know why, probably a personal vice.

there might be an invisible new line character in your database result?
using Do it would reveal it…

you do not use the same query the second time, do you?


Describes Where ?
Did You check errorocurred block ?

@Taifun I use the exact same query. In the notifier it works as expected. In the if/else statement, right below the notifier, it does not work the first time BUT it does work when I restart the application. Thus I have ruled out the new line character, as this would be obvious in either first, second, Nth run of the app. What I have not ruled out yet is whether the aliases to the images btn_green are correctly set via the assets or it takes time to find them… probably I’m wrong, just throwing out ideas. I’m really puzzled on this, cause the exact same part of block code was working perfectly in Appinventor… a loooong time ago. In order to give time to any background service, instead of pressing the “Settings” button after reading the note, I gave it a whole minute but nothing changed, once again in the first run after installation, the app fails on that specific issue but works as expected after restart without reinstallation of course.

@Rogerio_Rios The original table was created and tested via Notepad++ and tested in XAMPP correctly and used Rebase to convert to sqlite. I use a browser extension to manage any changes to the sqlite db. Don’t get me wrong the database and map work as expected from the first time, I can see it via the troubleshooting notifiers, the button or if/else statement has an issue, only the first time. BTW the error occurred block did not show anything.

I’ve had “problems” with if else (a long time ago) and these days with sqlite (days before the update the app just crashed and closed - it went back to work the other day).
So the first time the 2 selects return 1 ( number ) and still the "else’ block is executed (btn_gray) And in second the 2 selects return 1 ( number ) And (btn_blue) is executed ?

@Rogerio_Rios That is correct the first time the 2 ‘selects’ both return a ‘1’ (num) but the else is executed (btn_gray). The second time the select return ‘1’ (num) again but the ‘if then’ becomes true and the btn_green is executed.

I don’t know if it makes any sense to also let you know that there is another set of procedure which when the btn_gray or btn_green is clicked, it updates the db with a ‘0’ or a ‘1’ respectively so that when the app is restarted, it will read the user’s setting from the db and allocate the correct image (that is the procedure settings_clicked shared herein). Let me just say that the update does not function either the first time the app is executed but it works as expected the second time. It is like that btn_A****n.image is unable to process the ‘if then’ part of the statement.

Have you tested when 1 is a string and when it is a number?

is text?

is number?

@Rogerio_Rios Yes I tested it with both text block and number block but as expected the result is the same i.e. first run fails, second works like a charm.

@Taifun @Rogerio_Rios and anyone else interested.
I tried to use the tester to debug the app and I noticed a few things:

  1. There is a 908 error code when the app starts due to permissions to the external storage which neither of the phones used have as I’m using these with dual SIM. I will try removing one and use an SD card instead and keep you posted. Still this is not a blocker.

  2. The Kodular companion tester prompted on the phone that the table queried does not exist. So I thought that probably via the db is not getting imported or not set or not set at a folder expected. BTW as a reminder if the app is installed either via QR or USB connection NOT Kodular tester, these errors do not exist. Therefore this error might be directly related to the tester. Is there any way the db can be installed with the tester?
    Furthermore the ‘Do it’ prompted the following messages which captures the errors seen in the screen as well.

  3. For some reason the comparative block returned two results instead of one, which is a bit weird

  4. Even though the latest comparative result is ‘true’ the if/else statement is executing the ‘else’ instead of the ‘then’ and once again I get a btn_grey instead of a btn_green.

Any ideas?

NEW EDIT - As the tester did not give the wanted results, I proceeded by using several notifiers as a debugging method and found out that the first time the SELECT result is giving a wrong output.

Hence the if/else statement triggers the else part i.e. btn_grey.

The second time the app runs, that same query gives the following result…

Which triggers the ‘if then’ part which give the correct result i.e. btn_green.

So… again any ideas why this is happening? @Taifun at al times I’m using your execute.sql block as seen in the the initial images at the top of the post, any ideas why this might be happening?

7:53 am
It’s strange that the error ocurred block doesn’t return what the error was.
I’m trying to remember what this ‘uselect’ message is, I think I’ve seen it somewhere… :thinking:

@Rogerio_Rios do you mean that I used such a generic naming convention on the table which turned out that ‘uselect’ is a reserved name/label?

No.:pensive: I was saying that I think I’ve seen this “uselect” message (I think, I’m not sure).
And the errorocurred block?

@Rogerio_Rios I have this error_occured blocked… I hope it is enough to catch the error.
Error_occured block

But there is no actual error happening as the table/db can be accessed, the names and sql query are correct so no error. The problem comes because the result of the query instead of prompting the number 1, it actually gives, only the first time the result ‘uselect 1’. @Taifun @Rogerio_Rios I need to find a way of removing the ‘uselect’ from the result and regardless of the times the app is executed.

As an update I also rearranged the initialisation’s screen query in order to understand how @Taifun 's execute.sql block will react. The new init screen is… BTW the only change from the original is that I removed the " " double quotes from the WHERE id=“63”.

The result once again is a bit odd as instead of an error due to syntax or returning the value required, it actually returned… the name of the column which is not queried at all.

@Taifun is this normal? I will rearrange my blocks and work with the Chinook db in order for all of us to have a common reference point… who know maybe Rebase adds something in my sqlite file that is not expected.

@Taifun as said in the previous I will rearrange the blocks to work with the Chinook db…

Once again it demonstrates that something is failing the first time and the result instead of just the number, it returns also the name of the column… the correct in the following would be only 5.94 without the ‘Total’.

Ids are usually auto increment numbers.

Did you try show in one label or Textbox Component ?

Did You try Change " to ’ ?

InvoiceID is varchar ?

I think the correct thing is to show the field name and value. Not ?

finally you are using the companion app to test… you should have done this from the beginning… only implement a little bit of code and test immediately… only if it works, then continue implementing…

any screenshot of the error?
it looks like you are reading or writing from/to the internal (emulated) sdcard…

see Q11 here App Inventor Extensions: SQlite | Pura Vida Apps about how to import a database from the assets on Kodular… however starting with the latest release Kodular now uses /Kodular/assets as directory for the companion app for devices < Android 10 …

to find out, if the Import has been successful or not, use the ErrorOccurred event of the sqlite extension…

if you execute Do it twice, you get the new Do it result but also still can see the first Do it result…

If you get a result like uselect 1 then it looks like you did not set the property IgnoreHeader to true… uselect in this case is your column name… it looks like this is the bug you were looking for from the beginning…


1 Like

@Taifun @Rogerio_Rios mystery solved, as ever @Taifun was right. I will start by thanking you both as this is a long read and you may get bored and not reach the end ot this message. Your insights have been very helpful, thank you gentlemen.

To the moderators, this topic is considered solved and should be moved from the bugs to a special location called blooper made by this guy, with my face on it.

If you check the initial post you will see that once the firstrun notifier executes, it suggests to the user to go to the settings and once settings is pressed…
After choosing

As you can see the header.ignore is only included in the ‘else’ statement not the ‘then’ statement. I removed that ignore.header from there ‘AfterChoosing’ and placed it directly after the sqlite import is performed and problem solved.


any screenshot of the error?
it looks like you are reading or writing from/to the internal (emulated) sdcard…

Regarding the 908 error, I have no screenshot as it is very fast but…

see Q11 here [App Inventor Extensions: SQlite | Pura Vida Apps]App Inventor Extensions: SQlite | Pura Vida Apps) about how to import a database from the assets on Kodular… however starting with the latest release Kodular now uses /Kodular/assets as directory for the companion app for devices < Android 10 …

I followed the PuraVida instructions to the letter as you can see from the block code. The code may state that it will import to Makeroid in case companion is present but still, I can see all the assets being installed in the Kodular folder.


Ids are usually auto increment numbers.

Not in this db, I manually made a column with specific ids

Did you try show in one label or Textbox Component ?
Did You try Change " to ’ ?
InvoiceID is varchar ?

Nope I did not and since the solution was in the header.ignore (see above) then there’s no point in looking into it.

I think the correct thing is to show the field name and value. Not ?

When one tests the sqlite syntax with an sqlite manager or browser extension, the result should be the value alone as the headers are ignored by default. In Kodular and probably Android in general (? no idea), the developer have to specifically instruct for the headers to be ignored.

Once again thank you both gentlemen.

I have never used extension with Sqlite. There was an app crash and close issue when I was creating the table. I think it was solved by changing the SuppressToast property = true