Thursday, 29 August 2019

SQLite

You asked for it, so here a guide to SQLite.
Livecode can work with any database. Livecode has integrated SQLite, but you can interface with any database that has an ODBC interface (almost all have it), here are the most popular:
  • SQLite
  • MySQL
  • Oracle
  • PostgreSQL
  • Valentina DB

Databases are usually files outside our program that can be on the same PC on which our program runs or on a remote server. The databases contain lots of cataloged information. Thanks to the databases we can search for information, insert or delete data, all according to specific criteria that we set ourselves.
The language used by almost all databases is SQL. Generally the valid commands for a database also apply to all others.
Summarizing in a few words a database, we can say that it is a collection of tables, within each table the data are organized by rows and by columns.
Databases have advantages:
  • quick to find the data you need among thousands of data
  • take up little space
  • they are optimized to do their job
  • they are very fast (very, very, very fast)
  • it is possible to cross the data of several tables easily

You could do the same things as a database with an array; but if you deal with a lot of data, I suggest you learn how to use databases.

Connection

A database can be an external running program, you talk with it and it answers you. Thisi is called client/server database. (MySQL, Oracle, PostgreSQL)
A database can be simply just a file (SQLite).
To use a database you must first connect to a database (server or file), using the revOpenDatabase () function and store the connection identifier. For example with SQLite we will write:
put revOpenDatabase("sqlite", "./myDB.sqlite", , , , ) into connID


If livecode doesn't find the file, Livecode will create it.
In this example the connID variable contains the connection identifier (it's just a number). You can establish multiple connections simultaneously.

Query

To retrieve information from the database, in jargon it is said to query, just use the command the revDataFromQuery function, specifying how to separate rows and columns:

put "SELECT * FROM users ; " into tSQL
put revDataFromQuery(tab,return,connID,tSQL) into tRecords


in this case we have that tRecords contains all the data where each column is separated from the other by the TAB character and each row by a line. You can change this form, but it is very convenient because it allows you to view the data in a text field like a real table (field, label).

Execution

To execute commands that change in the database, or make more complex actions, just use the revExecuteSQL command, for example:

put "INSERT into users (name,surname) VALUES ('Jack','Sparrow')" into tSQL
revExecuteSQL connID,tSQL

Speeding execution

Sometime you need to send many commands one after another, like inserting a lot of data, or updating a lot of data. In this case is much better to use transactions. Transaction is a list of task, the database reads them all and then decide the best strategy to do all task in the shortest time possible.
For example:

put "BEGIN TRANSACTION;" into myQuery
put "INSERT INTO myTable (name, surname) VALUES ('Mark', 'Red') ;" after myQuery
put "INSERT INTO myTable (name, surname) VALUES ('John', 'Green') ;" after myQuery
--..... a lot of data more
put "INSERT INTO myTable (name, surname) VALUES ('Elvis', 'Yellow') ;" after myQuery
put "COMMIT;" after myQuery
revExecuteSQL connID,myQuery

Check  column existence

SQLite is simple fast, portable and compact, but it misses some complex function like how to know if a table column exists. You can do it, but it needs to call PRAGMA.
Here the example code:
put "PRAGMA table_info(myTable);" into tSQL
put revDataFromQuery(comma,return,connID,tSQL) into tRecords
if "muyColumn" is not among the items of tRecords then   
   answer "Column myColumn doesn't exist"
else
   answer "Column myColumn exists!"
end if

Close the connection

When working on databases installed on client/server type, it is advisable to close the connection when you no longer work with the database, here is the code:
revCloseDatabase connID


Friday, 23 August 2019

Livecode 9.5 stable

This version brings you a raft of new exciting features and benefits.
  1. New Android Architectures (32/64 bit) + support for the latest Google Play
  2. Store requirements. Create your app for the latest and greatest Android OS's, with fast simulators to help you preview and test.
  3. Windows 64 bit IDE & deployment support. Write code on and for 64bit Window's operating systems, ensuring your app is fast and smooth wherever it runs. LiveCode 9 has supported 64 bit on Mac, iOS and Linux for a while, now Windows can join the party.
  4. PDF Widget (Business Edition). A powerful full featured drag and drop widget to view and edit PDF files on desktop and mobile.
  5. Android Barcode Scanner Widget (Indy + Business Edition). Your Android apps can now scan barcodes just like your iOS apps.
  6. New Container Layer Mode. Build beautiful tables and grids that scroll fast and smoothly.
  7. New mobileSetKeyboardDisplay and
  8. mobileGetKeyboardDisplay handlers. Pan your screen view up to ensure your controls remain in view above the keyboard when needed.
  9. Progress, isSecure and allowUserInteraction features added to the browser widget. Need we say more? The beauty of the LiveCode language is that it is self explanatory.
  10. Several enhancements to Tree View Widget. You can now auto expand to reveal a row when selected and get and set the fold state of a specific row.
  11. Mac status menu library added. Use the new library to create, delete and set properties on a status menu.
  12. Improved sort international to support lots of additional locales. Useful if you are creating an app in several languages.
Additionally between version 9.0 and 9.5, Livecode squished over 400 bugs, giving you a noticeable boost in performance and stability.