PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

  • Overview
  • Creating a SQLite connection
  • Transferring data from a WINDEV application to an Android application
  • Copying a SQLite database found on the PC onto the mobile device
  • Copying the SQLite Android database onto the SD Card
  • Transferring SQLite data from an Android application to a WINDEV application
  • SQLite data found in the database directory of the Mobile device
  • SQLite data found on the SD Card of the Mobile device
  • Note: Creating an Android emulator with a SD Card
  • Example
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Overview
For the Android applications, the only available database is SQLite. To use a database, a SQLite connection must be declared in the data model editor. For the Android applications, the available databases are:
  • HFSQL (Classic and Client/Server),
  • SQLite.
    To use a SQLite database, a SQLite connection must be declared in the data model editor.

Creating a SQLite connection

A SQLite connection can be created:
  • When creating the analysis: When creating an analysis for an Android application, the database proposed by default is SQLite. In this case, the wizard automatically creates a connection used to manage and access this type of data file. The wizard allows you to enter the advanced parameters of this connection:
    • Name of the file containing the database.
    • Directory of the database.
  • In the data model editor, via "Analysis .. Connections". All you have to do is add a connection to a SQLite database and give its characteristics.
A SQLite connection can be created:
  • When creating the analysis: when you create an analysis for an Android application, the proposed database is either SQLite, or HFSQL (Classic or Client/Server). If you select "SQLite", the wizard automatically creates a connection used to manage and access this type of data file. The wizard allows you to enter the advanced parameters of this connection:
    • Name of the file containing the database.
    • Directory of the database.
  • In the data model editor: on the "Analysis" pane, in the "Analysis" group, click "Connections". All you have to do is add a connection to a SQLite database and give its characteristics.
When the connection is created, you will be able to use all the WLanguage functions for handling the data files as well as the possibilities of link with the controls.
Versions 16 and later
The SQLite databases ca be accessed from WINDEV or WEBDEV via the Native SQLite Access. Therefore, you have the ability to exchange data between the database of your WINDEV "Back Office" and the mobile database.
New in version 16
The SQLite databases ca be accessed from WINDEV or WEBDEV via the Native SQLite Access. Therefore, you have the ability to exchange data between the database of your WINDEV "Back Office" and the mobile database.
The SQLite databases ca be accessed from WINDEV or WEBDEV via the Native SQLite Access. Therefore, you have the ability to exchange data between the database of your WINDEV "Back Office" and the mobile database.
Note: From version 19, HFSQL is the new name of HyperFileSQL.
Transferring data from a WINDEV application to an Android application

Copying a SQLite database found on the PC onto the mobile device

When a SQLite data file is created by an Android application, the SQLite database is created in the "/data/data/com.<mycompany>.<projectname>/databases/<base>.db" directory.
This directory cannot be accessed from the PC: the Android system does not give access to this data.
To transfer a SQLite database found on the development computer to an Android device, the database can be added into the apk archive of the application. This operation can be performed when creating the Android archive, in the "Integrating files" screen.
This file can be installed on the Android phone as soon as the application is started by fExtractResource. For example, to install the database in the default directory of Android databases:
fExtractResource("MyPCDatabase.db", CompleteDir(fDataDir()) + "Database.db")

Copying the SQLite Android database onto the SD Card

When a SQLite data file is created by an Android application, the SQLite database is created in the "/data/data/com.<mycompany>.<projectname>/databases/<base>.db" directory.
To ignore this limit, we recommend that you use the SD Card of the mobile device to store the data.
To do so, you must modify the characteristics of the connection used, by specifying the directory of the SD Card. This operation must be performed by programming. For example:
gcntSQLite is Connection = MyAndroidFile..Connection
gcntSQLite..Source = CompleteDir(SysDirStorageCard()) + "Database.db"
gcntSQLite..Provider = hNativeAccessSQLite
This file will be accessible from the PC when the mobile device is connected to the PC. Therefore, you will be able to perform copies of the database from the PC to the mobile device (and conversely).
Transferring SQLite data from an Android application to a WINDEV application

SQLite data found in the database directory of the Mobile device

If the SQLite data to transfer is found in the default data directory of the Mobile device, the transfer must be performed by the Android application by using HTTTP requests (AWP service), an FTP transfer or via sockets.

SQLite data found on the SD Card of the Mobile device

In this case, all you have to do is copy the SQLite data from the SD Card (visible like a Windows disk) to the PC and include the data in the WINDEV application.

Note: Creating an Android emulator with a SD Card

For your tests, you have the ability to create a SD Card in the Android emulator:
  1. Start a command console window in Windows ("Start .. CMD").
  2. Position yourself in the "tools" directory of the Android SDK used.
  3. Use the following command line (for a SD Card of 256 MB):
    mksdcard.exe 256M c:\temp\sdcard.img
  4. In WINDEV Mobile, when starting the emulator, modify the command line as follows:
    -no-boot-anim –partition-size 128 –sdcard c:\temp\sdcard.img
Example
The following example allows you to use a SQLite database on Android with access to the database from a PC during the connection of the device in USB. The database is stored on the SD Card of the device.
// CntSQLiteDatabase is the name of the connection defined in the analysis

// Directories on the SD Card for accessing the SQLite database
sDataDirectory is string
sDataDirectory = "data_wm_androidsqlitedatabasesharepc"

// Name of the SQLite database
sNameSQLiteDatabase is string = "wm_sqlitedatabase.db"

// Unit corresponding to the SD Card of the Android device
// (from a Windows application)
// To be asked to the user
// and to be stored in a parameter file
sUnitSDCardFromPC is string = "e:"

// In any case, the database is in SQLite format
CntSQLiteDatabase..Provider = hNativeAccessSQLite

// Execution on the Android device?
IF InAndroidMode() = True THEN
// yes
// WINDEV Mobile simulator?
IF InSimulatorMode() = True THEN
// Database in the Exe directory of the project
CntSQLiteDatabase..Source = fExeDir() + ["\"] + sNameSQLiteDatabase
ELSE
// Execution on the Android device or on the emulator
// There should be a storage card,
// checks whether it is available
IF SysStatusStorageCard() = sysCardAvailable THEN
// Localizes the database on the SD Card,
// in relation to the mobile
CntSQLiteDatabase..Source = SysDirStorageCard() + ["/"] + ...
sDataDirectory + ["/"] + sNameSQLiteDatabase
ELSE
// No storage card
Error("No storage card available in write mode.")
EndProgram()
END
END
ELSE
// Execution on a PC?
IF InPocketMode() = True _OR_ InWindowsPhoneEmulatorMode() = True THEN
Error("No access to the database is provided on this platform")
EndProgram()
ELSE
// IF SysWindowsVersion() IN ("98","NT 3.5","NT 4", ...
// "NT 5","ME", "2003S","2008S","VISTA","7")  THEN
// localizes the database on the SD Card, in relation to the PC
CntSQLiteDatabase..Source = sUnitSDCardFromPC + ["\"] + ...
sDataDirectory + ["\"] + sNameSQLiteDatabase
END
END

// Open the connection
IF HOpenConnection(CntSQLiteDatabase) = False THEN
Error("Failure connecting to the SQLite Android database", ...
HErrorInfo())
EndProgram()
END

HCreationIfNotFound("*")

Info("Connection to the database established")
Related Examples:
Android Inventory Android (WINDEV Mobile): Android Inventory
[ + ] This application is used to perform inventories and to save the results in a database.
WM Registered Cross-platform examples (WINDEV Mobile): WM Registered
[ + ] This application is an attendance manager. It allows you to list the persons who attended a meeting.
The database is filled beforehand with the list of registered persons.
You have the ability to find a person by using his/her name.
The following topics are presented in this example:
1/ using a browsing looper based on a query
2/ using a database in HFSQL format.
WM Managing Orders Cross-platform examples (WINDEV Mobile): WM Managing Orders
[ + ] The WM Managing Orders example is a simplified management of orders and invoices.
This example is used to:
- create/modify/delete a product,
- create/modify/delete a customer,
- contact a customer by email,
- see the history of the actions performed for a customer
- place an order, print an order form,
- invoice an order, print an invoice.
WM Password Cross-platform examples (WINDEV Mobile): WM Password
[ + ] Web sites, bank accounts, ... passwords are everywhere in out life. With WM Password, no need to store all the passwords of your different accounts. The application stores all your passwords in a secure way. WM Password can also generate secure passwords for you.
WM Notes Cross-platform examples (WINDEV Mobile): WM Notes
[ + ] This example is using the drawing functions of WLanguage for Android and iOS.
It allows you to draw graphic "notes" and to save them.
WM Sports Cross-platform examples (WINDEV Mobile): WM Sports
[ + ] This example is a sport application used to save your performances.
The application calculates the distance, the time, the average speed and the number of calories spent according to the sport.
The run is displayed on a map control via markers and an itinerary.

The example also includes a server part used to synchronize the user data.
This webservice is available in the WEBDEV "WW_Sports" example.
WM Stocks Cross-platform examples (WINDEV Mobile): WM Stocks
[ + ] This application is used to perform stocktaking and to save the results in a database.
The example is used to create entries/exits in the stock, by directly scanning the bar code of products.
It is optimized to be run on tablets.
Minimum required version
  • Version 16
Comments
Click [Add] to post a comment