SQLite/Notifier/Button not working the first time

I checked out Kodular Fenix (v1.5.0) Bug Tracker before creating a new topic

Describe your issue

Hi all, I hope I’m not raising a red flag for something that escapes my doings, although I have tried a lot to find the failing cause to no avail. Basically, the app I made does not respond as expected the first time it is executed BUT it does work as expected the second with no problem. The app start with a screen… apologies for the black censorship but the customer does not want to reveal naming conventions.

So initialisation of screen → check if this is the first time → import sqlite via Taifun’s tools → Notifier for the user → Store value for first time → Additional notifier used ONLY for troubleshooting that the sqlite file was imported and that the database can be pinged (SELECT)… the rest part will work from the second time on.

The first notifier suggests to do something by pressing the ‘Settings’ button on the message so…
After choosing

Which calls the settings_clicked procedure which part of it is shown herein…

Loads of vertical/horizontal are set to false/true (these work as expected).

  • The notifier in the green square is used only for troubleshooting that the db can be still pinged and it works as expected.

  • The red square is the same sql query as above and it is supposed to give a green image if the sql query returns 1 which is TRUE set in the db manually. The problem is that the first time the app is executed/loaded, that button does not turn green. The second time the app is restarted that button goes green as expected and hence the issue.

Steps to reproduce the issue

I have tested that issue on Android 7 and Android 10 phones. I have downloaded and installed the app via the QR code given scanned by the phone’s QR scanner and Kodular scanner. I have downloaded the apk to computer and upload it to the phones via USB. I have changed the notifier to a custom message and changed the after choose to after message to no avail. Instead of pressing ‘Settings’ I press cancel to follow another root and the return to the same sttings_click called from another route but still that doesn’t work the first time even though the db is fully loaded and tested.

Expected Behaviour

Once the procedure setting_click is called, it should show that this button and all other buttons (not shown here as the list is too long) going green_img or other colour according to the db entries.

Actual Behaviour

The app doesn’t work the first time BUT it does work as expected the second time and so on.

Show your Blocks

Blocks shown above with description

Android version

Tested on Android 7 and Android 10

where above? I could not find it anywhere else…
if you use the same query twice, then you should put it into a procedure and call that procedure in all cases…
also what exactly will be returned from the Execute statement? A Do it result would help…
try to simplify your tests to locate the issue…
which Android version are you using for your tests?


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