|
FORUMS PROFESSIONNELS WINDEV, WEBDEV et WINDEV Mobile |
| | | | | |
Windev mobile how to use SQLite for android on the local device |
Débuté par ELIJAH ( Andersons P, 04 mai 2012 13:26 - 2 réponses |
| |
| | | |
|
| |
Membre enregistré 5 messages |
|
Posté le 04 mai 2012 - 13:26 |
I have been working for a while do to this. I guess it was so hard for me because i just got this software a week ago.
My issues were: 1. Having a local database (SQLite) on the android device and pulling data from it 2. When i looked at the examples the WM team used HFSQL with no SQLite databases embedded in it. SO here is a fix, i am sorry if it is not perfect, but it is working great for me.
Just follow along, i will have code as well as a link to my site to download a source file of the project. Note at the time i am using Windev Mobile V17 Beta. I am making this as simple as i can, so some things might be "out of the normal order" but it is the fastest way to input and develop.
1. Create a new android app, The only setting i care about is the database settings. Just say no database.
2. Create a window and name it what ever you want.
3. In the project explorer under Procedures go ahead and New set of global procedures, name it "pglobal".
Then while that file is highlighted create a minimum of three(3) new procedures. Name them the following:
FileConnection
TableData
Creation
!!make sure pglobal was highleted!!
Now that that is complete, go ahead and minimize the code, now we are going to set up the rest of the environment.
4. On the Left of the Project Explorer you will see the icon for analysis, Click on it then click on "Click here" to create an analysis.
Select "Create a new description of data file" Set up everything as HFSQL!!
Now add another data connection NAME THIS ONE "MYCONNECTION"!!!!!
use this to create the connection to your SQLite database. Make sure the database path is <application directory> and make sure you have the correct database name. It doesn't matter if it tells you that it didnt find the database, you are just setting up a connection to A SQLite database for the program to use.
5.Add a looper to your window that you created. -- Make sure the looper is sized correctly, both the data blocks and the caption or it will give errors later
6. Now we add some code. this code will be added to your FileConnection procedure
IF InAndroidMode() THEN IF
HDescribeConnection(MyConnection1,"","","YouDataBase.sqlite","",hAccessSQLiteAndroid,hOReadWrite) = False THEN Error("Unable to describe the connection", HErrorInfo(hErrMessage)) EndProgram(True) END IF HChangeConnection("*",MyConnection1) =False THEN Error("Unable to change the connection", HErrorInfo(hErrMessage)) EndProgram(True) END
END
IF HCreationIfNotFound("*") =False THEN Error("Unable to create the data files", HErrorInfo(hErrMessage)) EndProgram(True) END
7. Now we will do the code for the tabledata procdure
Procedure TableData()
tablename.fieldname1 = "String of information"
HAdd(tablename)
tablename.fieldname2 = "String of information"
HAdd(tablename)
tablename.fieldname3 = "String of information"
HAdd(tablename)
tablename.fieldname4 = [ alot of lines of text this is a new line same field this is another one ]
HAdd(tablename)
8. Now we are going to add the code for our Creation procedure
Procedure Creation(sWindow is string)
HCreation(TableName)
TableData()
Close(window)
9 This last portion is placing these global functions where they need to be to operate properly
In the drop down menu at the top where you select from different code modules, choose the one that is named what ever you named your application
This code is being input under "Initilization of your app name"
fileconnection()
Next go to the same place for the window you created "Initilization of your window name"
tabledata()
Providing you did this correctly, when you test this out in your android emulator, or debug it on your device. It will load up your window with the populated data.
I am working on a tutorial that works the same way, but with prepopulated *.db files so you do not have to code in each field in the module. I really hope this was helpful and i hope people take after this and post more tutorials in this format so that anyone picking up this software can easily integrate.
To ensure this tutorial was exact in every step, I started a new application from scratch and followed this tutorial verbatim, the source code for this is at
www.andersonspc.com/tutorials/Tutorial1.zip
Email me with your source code and tutorials if you want them available for download too
Elijah Anderson phreaklulz@gmail.com |
| |
| |
| | | |
|
| | |
| |
Posté le 07 février 2014 - 11:39 |
The Creation Procedure doesn't work with me.
Procedure Creation(sWindow is string) there a problem on sWindow .. what should i do ? |
| |
| |
| | | |
|
| | |
| |
Posté le 05 janvier 2016 - 06:40 |
The download link does not appear to work. I get page not found. |
| |
| |
| | | |
|
| | | | |
| | |
| | |
| |
|
|
|