SQLite scripts: How to read/execute a SQLite script
SQLite script FAQ: How do I read/execute a CREATE TABLES
script from the SQLite command line? (How do I read or execute commands in a file from the sqlite3
command line?)
SQLite script FAQ: How do I read/execute a CREATE TABLES
script from the SQLite command line? (How do I read or execute commands in a file from the sqlite3
command line?)
SQLite FAQ: How do I create comments in SQLite?
SQLite lets you create comments using two different constructs, either two hyphens in sequence ("--"), or the "/.../" C-style comments. Here are examples of each approach, with the SQLite comments preceding the two database table definitions:
SQLite database FAQ: How do I create a SQLite database?
Creating a new database in SQLite is so easy, it's amazing. Once you have SQLite installed and your PATH set up properly, from your Unix or DOS shell, just issue a SQLite command like this:
SQLite FAQ: How do I list the tables in a SQLite database?
To generate a SQLite tables list, just log into your SQLite database with the sqlite3 command, and then issue the "tables" dot command:
Android/SQLite FAQ: How do I show a list of SQLite database tables from the Android command line (adb shell)?
You can show a list of SQLite tables by starting the Android adb shell (command line tool), and then properly invoking the sqlite3 command. Here's an example of how this works, with comments shown before each command:
SQLite FAQ - How do I create an autoincrement field in SQLite?
You define a SQLite autoincrement field (also known as a serial, identity, or primary key field) with this syntax:
SQLite schema FAQ: How do I list the schema for SQLite database table?
To view the schema for a SQLite database table, just use the SQLite schema
command, like this:
SQLite dump/backup FAQ: How do I backup (dump) a SQLite database (or database table)?
"How to make a backup of a SQLite database?" is a really interesting question. Because a SQLite database is really just a file, if you truly want to make a backup of that database, it can be as simple as copying that file to a backup location.
But there is more to the story ...
SQLite CSV FAQ: How do I import a CSV file into a SQLite database table?
If you’re not using an autoincrement (primary key) field in your database table, importing CSV file data into a SQLite database is straightforward, though you may have to do some work to clean up your data first. Let’s take a look at how this works.
As a first example, assume that I have a SQLite database table defined like this:
SQLite autoincrement FAQ: How do I get the autoincrement value from my last SQLite INSERT
command?
You can get the integer value of the primary key field from the last insert into an autoincrement field using a SQLite function named last_insert_rowid()
, as shown in the example below.
SQLite FAQ: How do I default a SQLite datetime field to the current date and time? (i.e., how do I default it to now?)
Just use the SQLite current_timestamp function, like this:
last_updated datetime default current_timestamp
In a more complete create table example I just used on an Android project, this looks like this:
SQLite database FAQ: Can you show me an example of the SQLite CREATE TABLE
syntax?
Sure, here's a small collection of SQLite CREATE TABLE
examples I recently created for my other SQLite tutorials:
This is a collection of notes about what I learned today, February 23, 2015. Most of it is about Android.
When (a) adding, editing, or deleting items in a ListView
and (b) using a CursorAdapter
, I need to update my cursor object before calling notifyDataSetChanged
.
I created this method, which I call from my fragment’s onResume
method:
SQLite FAQ: Can you show me how the SQLite ALTER TABLE
syntax works?
At the time of this writing you can use the SQLite ALTER TABLE
syntax for two purposes:
For other changes you'll have to follow some workaround procedures (discussed below).
My old iPad 2 was, well, old, and it’s slow speed was driving me crazy. So I decided to buy a new tablet, but when I made that decision I also decided to look around, and in short, I eventually decided to buy a Google Nexus 9. After a few days with it, here’s my review of the Nexus 9.
The Nexus 9 unboxing experience was a non-experience. The Nexus 9 comes in a simple, unattractive box, and there’s nothing special about any part of the unboxing experience.
It turns out that it’s easy to create and use a static array of strings in Android. Of course you can do this in Java code, as I describe in my Java string array tutorial, but for Android I’m talking about doing this in XML.
In short, this is how you define a static string array in an Android XML file:
As Android programming goes, creating an options menu item/button in the Android ActionBar is fairly straightforward. In this brief tutorial I’ll demonstrate all of the steps needed to add a new menu item to the action bar.
The first step is to declare what the menu “view” is going to look like. This is very similar to defining other Android views, you do it with an XML layout file.
Creating a Preferences screen in Android isn’t too hard. The website rominirani.com has a very good preferences tutorial that just needs a minor update for Android 5, as a piece of the code shown there has been deprecated.
To create an Android Preferences UI, just follow these steps:
[toc]
Filed under “What I learned about Android today,” it turns out that you can display an HTML string in an Android TextView
. However, this approach has major limitations, and you’ll probably want to display your HTML in a WebView
instead.
Skipping past that issue for a few moments ... if you want to try to display an HTML string in a TextView
, you need to use the Android Html.fromHtml()
method, as shown in this code: