When working with the SQLite database in Titanium, there are at least 3 kinds of names that you’ll be dealing with. Because some of these names can be the same (but don’t need to be), this can sometimes get confusing. Here’s the story on how this naming stuff works.
First, there’s the name of the database file. This is where the SQLite database is stored, and it holds all the records of your database. This name is what you’ll pass to Titanium.Database.open(). You can have more than one database file, with different names.
The next name we’ll consider is the name of the table (which we often also call the “database”) that’s stored in the database file. There can be multiple tables, with distinct names, in the database file. But often, there’s only one table, and many people will use the same name for this table as for the database file itself. This table name is understood by SQLite, and not by any variables in your program. It’s ok for the table name to match the filename, but it’s also ok for these names to be different.
The return value of Titanium.Database.open() is your reference to the database file, and you’ll store that in a variable in your app. Again, some people might use the same name for this as for the database file and/or a table within the database file. In the sample apps, we try to use distinct names just so you don’t get the idea that the names all have to be the same.
Finally, there’s the return value from the db.execute() call, which will be your result set. This is often something like db.execute(‘SELECT …’) to select specified rows from the database table. The reference to the ResultSet will be stored in a variable, and so will have a distinct name from the variable used to store your reference to the database file.
In the sample program in our Database API Reference Guide, all four of these have distinct names—the database file is
cold, the table within the database file is
coldBeverages, the return value from
coldDB, and the result set is