Android Question Simple database example?

cougar

Member
Licensed User
Longtime User
First off, thanks for all of the useful information I have picked up through this forum and the various tutorials. B4A is an incredible development environment and I look forward to learning even more in regards to its capabilities. I am a former VB programmer so the similarities between VB and B4A are greatly appreciated. I do have a question, however, regarding databases.
I have read through numerous tutorials and downloaded several database examples. They are great and I do appreciate them. However, I have seen numerous posts in the forum from "newbies" like myself that seem to be seeking the same basic database info I am but who are presented with very robust examples that can be a bit confusing to someone who is looking for a simple example. So, if at all possible (for both myself and future B4A newbies) I would love to see a simple example that presents the following. For those familiar with the old VB/Access sample programs (CD collection, contacts, etc.) this should be easy to pick up on.

A layout (form to VB programmers) that consists of a textbox and a button at top. The button will read Create Database. The user enters the name they want for the db in the textbox and, upon clicking the button, the database is created. For simplicity, let's say the database has 3 fields (First Name, Last Name, Middle Initial).

The layout also includes three textboxes (labeled as First Name, Last Name, Middle Initial). These textboxes will obviously display the fields from the database.

Beneath these fields are the familiar buttons from VB...Add New, Update, Move Next, Move Previous, Delete.

The database would simply allow the user to add a record, and navigate through those records, as well as delete a record if need be.

What I see in all of the examples are tables that allow the user to click on the table and then open an edit or filter screen/layout. The above example would be different. It would start with the Edit layout and avoid the table view, scrollviews, filter screen, etc. These components are great but sometimes a simple viewing of the database (via fields) is what's called for rather than a table view. However, it would be nice to have an additional button that would allow the user to see the data in a table as long as the table is not the focal point of the database and the user can easily return to the main layout (the edit layout).

Again, I appreciate the great examples and I have learned a good deal already but the simple example above, minus all of the scrollviews, tables, etc. would be a great way to show just how functional database work is in B4A and provide those like myself with a starting point to build from.

Thanks again for your assistance. I do apologize if in all of my searching I have overlooked the basic example above. I look forward to your response.
 

klaus

Expert
Licensed User
Longtime User
The example I posted is the simplest one, with the simplest user interface.
The logic for user interfaces is often different from one person to another.
Feel free to adapt it to your 'feeling' or requirements, that's the purpose of the project.
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Thank you Klaus.. I am inspired to also work hard to contribute with something that others can
benefit from.. up to now I just consuming.
 
Upvote 0

John Morgan

Member
Licensed User
Longtime User
The example I posted is the simplest one, with the simplest user interface.
The logic for user interfaces is often different from one person to another.
Feel free to adapt it to your 'feeling' or requirements, that's the purpose of the project.

Thanks Klaus for providing a simple example. Unfortunately I cannot get it to run properly. It compiles and appears on the emulator as you presumably intended but with nothing in the ID/FirstName/LastName?City boxes.

I am new to SQLite.
I do see error messages in the log which indicate that the persons table is not recognised. Part of the error message is:

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 86 (main)
mainafterFirstLayout (java line: 104)
android.database.sqlite.SQLiteException: no such table: persons (code 1): , while compiling: SELECT max(ID) FROM persons

I have tried opening up the database with 'SQLiteExpert' and I see the table is prefixed with 'main.' I have tried the line
DBTableName = "main.persons"
but that too gives an error message.

I would be most grateful for some help on my problem - probably staring me in the eye if I only could see it,
Best wishes, John M.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
@John Morgan
When you first run the program all EditText views are empty.
Enter data and click on the Add button.
Then change data and click the Add button.
If you want to change data select the entry, modify the data and clcik on Update.

That's it.
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Hi John,
make sure the path of the database is correct.. on my computer the example is running perfectly
without modification.. I just run it as is.
Good luck.
 
Upvote 0

John Morgan

Member
Licensed User
Longtime User

Hi John,
make sure the path of the database is correct.. on my computer the example is running perfectly
without modification.. I just run it as is.
Good luck.



Thank you Klaus and Beja,

I appreciate your help.

I have looked at it again and downloaded Klaus's SqlLiteLight1.zip and tried running it - all works perfectly.

I have a number of test databases filed and I am wondering whether somehow or other I have used the wrong database for the previous download. Anyway I will not waste further time on it as all I am looking for is a simple example to get me going - just what you have provided.

Thanks Klaus for your work, I have downloaded the two pdf manuals of yousr and they are very useful,

Best wishes, John M.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…