Android Tutorial New Easy to Use DataBase Functions V1.0 with Samples

* * * UPDATE * * *

July 8th, 2012 - New DataBase Class http://www.b4x.com/forum/additional-libraries-classes-official-updates/22118-class-databases.html



JUST POSTED - The New Easy DataBase V1.6 Functions with Samples and Full Working App! - September 3rd, 2011 5:00 PM

Just added some new date functions per request to Version 1.6. The 1.6 sample is attached below. It now includes these new date functions:

db.Date() --- Returns the current date
db.DateNew("09/03/2011", 30) --- Returns a new date from any selected date, enter positive or negative numbers as second parameter
db.DateNOD("09/03/2011", "03/11/2009") --- Returns the number of days between any two dates passed to it

See Post # 24 for other details: http://www.b4x.com/forum/basic4andr...sy-use-database-functions-v1-0-samples-3.html


Hello All. I just added Version 1.2 to this post. I found a bug that the db.pointer did not update correctly depending on the sorted results in the db.AddRecord and db.UpdateRecord functions. This has been corrected. I also made all functions not return any exceptions if you called them and the database didn't exist. It returns a Toast message stating that the file could not be found.

*** Older Post ***
I Just added Version 1.1. It has a few new things added and the variable names corrected to be more in line with the other functions. In version 1.1:

db.Pointer
db.RecordCount
db.FilePath
db.FileName
db.Field

I have also moved all variable declarations out of the main project. This leaves a totally clean main module to work in. All support for the database is now in the code module. I have attached a new Zip of version 1.1 but I also left the original. I changed over to 1.1 just this afternoon and went through it pretty quick. I feel it is tested and working just as it should, but I went through it quick. Please let me know if you find any errors or issues and I will fix them.

*** Original Post Below **************************************

Hello All,

No extra libraries are needed, just the CORE B4A library. I have tested some of the functions on my NookColor with up to 2500 records. With 2500 records, it moves very fast and searches are instant. All data stored will be in string format, however, you will be able to store links to images, web pages, etc. I wrote and posted the Strings functions here: http://www.b4x.com/forum/basic4android-getting-started-tutorials/10365-string-functions.html, and these functions will work in a similar way.

The functions and sample code are now attached. Some benefits may be that it is easier for new users to learn and less overhead on the processor. You don't have to learn SQL, etc. and the code required for each function is much less. Each device will have its limit on the number of records you can have before the system slows down, based on memory and processor. This will do just fine for most apps and contacts style programs. If you need to save images, objects, etc. directly into the database this will not work for you. You can have as many fields of any size as B4A and Android will support. It will also include the s.GenerateRecords(1000) functions, so you can populate the database with hundreds or thousands of records to test how the app performs under max load. Also, the database handles the pointer for you, it also handles BOF, EOF and no records in the database. It makes your coding job much easier!

If you have problems or questions, please post them and I will try to help. Hope you find it useful!:sign0089:

___________________________________________________________________
db.AddRecord()

db.DeleteRecord()

db.Exist()

db.FindRecord()

db.GenerateRecords()

db.GetRecord()

db.GetStructure()

db.ListRecords()

db.UpdateRecord()

db.FirstRecord()

db.LastRecord()

db.PreviousRecord()

db.NextRecord()

*** Added in Version 1.1 ***

db.Pointer

db.RecordCount

db.FilePath

db.FileName

db.Field

___________________________________________________________________


Thanks,

Margret

If you are using a version less than 1.2, please download the newest version, db.pointer issues were found in previous version(s).
 

Attachments

  • ADR.DataBaseProgram_1.5.zip
    12.6 KB · Views: 1,744
  • ADR.DataBaseSample_1.6.zip
    9.3 KB · Views: 2,146
Last edited:

margret

Well-Known Member
Licensed User
Longtime User
* * * UPDATE * * *

After the release of B4A 2.0!! I started looking into converting this DataBase code module to a Class. What I found was the power to really add to and make a much better DataBase Class with many new features. It will be much easier to use than this one! Just wanted to post so those that have B4A 2.0+ will know to look for the new DataBase Class soon. It still may be a few weeks out but I have a large portion already done. I can't say that it can or will be done, but you are welcome to throw ideas my way.

Thanks:D
 
Last edited:

myriaddev

Active Member
Licensed User
Longtime User
I would like to test early

Hi Margret. I have your older code in use and would be glad to pay you back
by offering to test the newest code early for you!
Jerry
 

Gearcam

Active Member
Licensed User
Longtime User
Hi this looks very good i will wait for the new version

will it be able to hold the actual bitmap into database ?

Will it work with MS sql through HttpUtils2 - Web services ?

Steve
 

Gary Miyakawa

Active Member
Licensed User
Longtime User
Margret,

I'm starting a project that needs a DB handler.. how close is your class version?

Thanks,

Gary M
 

young61

Member
Licensed User
Longtime User
Beta Database Class

Margret, I would like to try using your database class. Would you please send it to me? Thanks in advance,

Chet

Hello Gary M,

It is far enough along that I can get it to you to start using as a Beta.
 

metrick

Active Member
Licensed User
Longtime User
Margret, I am working on project that use database.
Could you please send your database class to me?
I would like to beta test it.
Thanks
 

gleepy

New Member
Licensed User
Longtime User
Hello Gary M,

It is far enough along that I can get it to you to start using as a Beta.

Hi Margret,
I would appreciate it if you could send me a beta version please.

I'm hoping it will save me quite a bit of time and for that... Thank you for all your selfless efforts on this.:sign0142:

John
 

spezialmaterie

Member
Licensed User
Longtime User
Hello,

i have a question. i want to use a database (read only) on my app.

i want to put the data sets with my computer to the database and then i want to copy the database to my tablet and use it there read only.

can i fill the database with a program on my computer?
 

microbox

Active Member
Licensed User
Longtime User
error in adding record...

Hi, thanks for this library...I'm trying to add record, table with 2 fields but I'm getting error.
B4X:
Sub Create_Click
If EditText1.Text <> "" AND EditText2.Text <> "" Then
db.Field(0,0) = EditText1.Text.Trim     
db.Field(1,0) =   EditText2.Text.Trim
db.AddRecord()
Else
ToastMessageShow("Empty field",False)
End If
End Sub
This is the error showing in the image below...hope you can help.
 

Attachments

  • Database_error.png
    Database_error.png
    14.8 KB · Views: 324

margret

Well-Known Member
Licensed User
Longtime User
You can create the database in notepad. Use the program to create one or two records and copy it to the root of the SDCard. You can then copy the file to your computer or email it. Open it with notepad and you will see the layout to follow.


Hello,

i have a question. i want to use a database (read only) on my app.

i want to put the data sets with my computer to the database and then i want to copy the database to my tablet and use it there read only.

can i fill the database with a program on my computer?
 

aklisiewicz

Active Member
Licensed User
Longtime User
seems like it is what I was looking for, but I'm looking for some (more realistic example - the one attached is not very helpful for beginners)
- creating database
- creating tables
- basic CRUD operations
- search and using Views, stored procedures etc.
anything like that available ?
 

GMan

Well-Known Member
Licensed User
Longtime User
i am using 2 fields in the db with decimal content, once is a money sum and the other a weight sum (both with 2 places behind the comma(dot)).

How can i add the depending sums to an total, to display them in a label after the the screen starts ?
Then the total amount of weight and the total amount of money should be displayed in a label...
 

nypaulie

Active Member
Licensed User
Longtime User
Can the *.dat files created using this program be edited? I've tried using text-editing but the altered files give an error msg when used in the program.
 
Top