All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codename1.db.package.html Maven / Gradle / Ivy

There is a newer version: 7.0.161
Show newest version


  
    
  
    
        

SQLite database access API

Most new devices contain one version of sqlite or another; sqlite is a very lightweight SQL database designed for embedding into devices. For portability we recommend avoiding SQL altogether since it is both fragmented between devices (different sqlite versions) and isn't supported on all devices.

In general SQL seems overly complex for most embedded device programming tasks.

Portability Of SQLite

SQLite is supported on iOS, Android, UWP (Universal Windows Platform), RIM, Desktop & JavaScript builds. However, the JavaScript version of SQL has been deprecated and isn't supported on all platforms.

You will notice that at this time support is still missing from the Windows builds.

The biggest issue with SQLite portability is in iOS. The SQLite version for most platforms is threadsafe and as a result very stable. However, the iOS version is not!

This might not seem like a big deal normally, however if you forget to close a connection the GC might close it for you thus producing a crash. This is such a common occurrence that Codename One logs a warning when the GC collects a database resource on the simulator.

Using SQLite

SQL is pretty powerful and very well suited for common tabular data. The Codename One SQL API is similar in spirit to JDBC but considerably simpler since many of the abstractions of JDBC designed for pluggable database architecture make no sense for a local database.

The {@link com.codename1.db.Database} API is a high level abstraction that allows you to open an arbitrary database file using syntax such as:

Some SQLite apps ship with a "ready made" database. We allow you to replace the DB file by using the code:

You can then use the {@link com.codename1.io.FileSystemStorage} class to write the content of your DB file into the path. Notice that it must be a valid SQLite file!

This is very useful for applications that need to synchronize with a central server or applications that ship with a large database as part of their core product.

Working with a database is pretty trivial, the application logic below can send arbitrary queries to the database and present the results in a {@link com.codename1.ui.table.Table}. You can probably integrate this code into your app as a debugging tool:

Querying the temp demo generated by the SQLDemo application Issuing a query




© 2015 - 2024 Weber Informatics LLC | Privacy Policy