Android Tutorial DBUtils - Android databases are now simple!

peacemaker

Expert
Licensed User
Longtime User
Where can I find latest version. In list of libraries link for DBUtils is leading to this post. In attached zip there is no xml or jar files. How to install this library?
It is not alibrary, it is the class module, to be added via "Project" menu. And used via the name "DButils" after activate SQL and JSON libs.
 

Dario126

Member
Licensed User
Longtime User
I was mislead because I had "DBUtils v1.0" installed in Libraries from before (not sure how), and expected same for new version. Thank You ..
 

Sathish VM

Member
Licensed User
Longtime User
Hi,

I'm using
B4X:
sqlLocalFile.BeginTransaction
strQuery =    "update stockreturns set threeyly = ( Select 100* (price/last - 1) from stockprice join " & str3YrTableName& " on symbol = sc_code where stockreturns.[Symbol] = stockprice.[Symbol] )"
DBUtils.ExecuteMemoryTable(sqlLocalFile,strQuery,Null,0)
sqlLocalFile.EndTransaction

I'm quite sure this command updates the Data.db file that sqlLocalfile refers to, since I'm able to read this data and show it in Android screen. However when I try to open the Data.db file after closing the application, SQ Lite Expert Personal tells me the below.



I'm able to open the file in Sqlite3 command line, dump the file as sql statements and then recover the Data.db file, but then I see that stockreturns table, that the DBUtils command updates, is empty.

Could this be because I never close the sqlLocalFile anytime? If I have to close it at the time of application close, in which activity/event should I put the code in?

I see Activity_Create but I don't see any Activity_Close in B4A? Do I have to code it myself?
 

Philip Prins

Active Member
Licensed User
Longtime User
I do a HTTP request and write it to DB , it works but stops everytime after 5000 updates?
I get the following error:



dbutils_updaterecord (java line: 709)
android.database.sqlite.SQLiteCantOpenDatabaseException: error code 14: unable to open database file
at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:95)
at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:73)
at anywheresoftware.b4a.sql.SQL.ExecNonQuery2(SQL.java:84)
at com.sample.SigFoxTD1205v2.dbutils._updaterecord(dbutils.java:709)
at com.sample.SigFoxTD1205v2.sigfox._devicesbytype(sigfox.java:388)
at com.sample.SigFoxTD1205v2.sigfox._jobdone(sigfox.java:669)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.keywords.Common$5.run(Common.java:958)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4624)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: java.lang.RuntimeException: android.database.sqlite.SQLiteCantOpenDatabaseException: error code 14: unable to open database file
at anywheresoftware.b4a.keywords.Common$5.run(Common.java:961)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4624)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: android.database.sqlite.SQLiteCantOpenDatabaseException: error code 14: unable to open database file
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.keywords.Common$5.run(Common.java:958)
... 9 more
Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: error code 14: unable to open database file

Or i get error
java.io.FileNotFoundException: /data/data/com.sample.SigFoxTD1205v2/cache/506: open failed: EMFILE (Too many open files)


I cannot find the reason,
 
Last edited:

Reviewnow

Active Member
Licensed User
Longtime User
New DbUtils Feature
Export SQLite tables to xml
Required xmlBuilder Library http://www.b4x.com/android/forum/attachments/xmlbuilder-zip.11015/

ExportTableToXml - Export the contents of a table to a single xml file
ExportTableToXmlString - Usefull for posting the entire contents of a table to a remote server for parsing / web services
ExportDbToXml - Exports every table in the database to a single xml file usefull for backing up your database

More instructions and examples are provided within the attachment look at the procedure exporttoxml in the main activity

These functions work as intended but if anyone has enhancements or suggested changes please feel free to let me know.
 

Attachments

  • DBUtils.zip
    19.6 KB · Views: 624

pantaraf

Member
Licensed User
Longtime User
Hi everyone, if I'm not completely wrong I think I have found a bug or, at least, an annoying limitation in DBUtils.
In the case of a query where there are two (or more I guess) columns with similar name, the map object will be loaded only with the first one. Let me explain with a pratical case:
B4X:
Dim m as Map
m.Initialize

m=DBUTILS.ExecuteMap(SQL,"SELECT A.ID, B.ID FROM TABLE1 A, TABLE2 B",Null)
In this case inspecting m will show that only an "ID" field has been loaded and not "A.ID" and "B.ID" as the SQL statement actually returns. Accessing m.GetValueAt(1) will, of course, throw an exception.

The simpler way to work around this limitation is to rename similiar columns using SQL

B4X:
Dim m as Map
m.Initialize

m=DBUTILS.ExecuteMap(SQL,"SELECT A.ID AS JIM, B.ID AS JOE FROM TABLE1 A, TABLE2 B",Null)
In this case the map object will be loaded correctly using "JIM" and "JOE"

Ciao.
Raffaele
 

Myr0n

Active Member
Licensed User
Longtime User
Thank you so much for this wonderful module
 

IslamQabel

Active Member
Licensed User
Longtime User
what is that tool? In GPS tutorial , you advised me to record my data on txt file or use database which is better...now i want to show the contents of database file which is stored my mobile or how to open it in the app?
 

Myr0n

Active Member
Licensed User
Longtime User

walterf25

Expert
Licensed User
Longtime User
Hi Erel and everyone else who may be able to answer this question, i'm working on an app which requires a listview, i purchased the Ultimate ListView and although i love it i'm having a performance issue with this listview, i have over 10000 items that need to go on that list, unfortunately the list takes around 15 seconds to load all the items. I just tried loading those items using the webview and the DBUtilities class and it works way better, the 10000 items load in under a second.
Now my questions are the following
#1 how can i adjust the width of the columns?
#2 is there a way to insert other views in the webview, ie checkbox
#3 How can i retrieve when pressed on a cell the information contained within.

If anyone has dealt with this before, i'd like to hear about it and thanks so much in advance for your help.

Thanks,
Walter
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…