background preloader


Facebook Twitter

Mostrar datos SQLite. Tutorial 46 en Español. Desarrollo de Aplicaciones Android. Creating multiple sqlite database tables in Android. Most of the Android database examples you will find on the web will usually contain only one table to demonstrate the basic database concepts.

Ver blog tiene cosas muy interesantes – diegounanue

That's great, the only problem with this is that most non-trivial database implementations will contain more than one table.

Creating multiple sqlite database tables in Android

The standard database creation string for a single table will probably look a lot like the below:private static final String CREATE_TABLE_1 =" create table " + table1 +" (_id integer primary key autoincrement," +" title text not null, body text not null);"; Which is called in your DB Adapter class like this: @Overridepublic void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_TABLE_1);} So what to do if you want to create more than one table? Bases de Datos en Android (III): Consultar/Recuperar registros. En el anterior artículo del curso vimos todas las opciones disponibles a la hora de insertar, actualizar y eliminar datos de una base de datos SQLite en Android.

Bases de Datos en Android (III): Consultar/Recuperar registros

En esta nueva entrega vamos a describir la última de las tareas importantes de tratamiento de datos que nos queda por ver, la selección y recuperación de datos. De forma análoga a lo que vimos para las sentencias de modificación de datos, vamos a tener dos opciones principales para recuperar registros de una base de datos SQLite en Android. La primera de ellas utilizando directamente un comando de selección SQL, y como segunda opción utilizando un método específico donde parametrizaremos la consulta a la base de datos. Para la primera opción utilizaremos el método rawQuery() de la clase SQLiteDatabase. Este método recibe directamente como parámetro un comando SQL completo, donde indicamos los campos a recuperar y los criterios de selección.

Ver si una tabla esta vacia. So I'm working on a game for android and I'm currently stuck at the 'load savegame' button in the main menu.

Ver si una tabla esta vacia

This button calls methods that read data from the database and write it into a resource class from which on this data will be accessed. The problem is: I want to disable the load button if there are no rows in the tables, which means that no savegame exists. To do this I used the following method: public boolean checkForTables(){ boolean hasTables; String[] column = new String[1]; column[0] = "Position"; Cursor cursor; cursor = db.query("itemtable", column, null, null, null, null, null); if(cursor.isNull(0) == true){ hasTables=false; }else{ hasTables=true; } return hasTables; As you can see it starts a query on one of the database tables and checks if the 0-column, which is the only one that should be in this cursor, is null. How to create SQLite foreign keys. By Alvin Alexander.

How to create SQLite foreign keys

Last updated: Oct 8, 2013 SQLite foreign keys FAQ: Can you show me how to define foreign keys in a SQLite database table design? The SQLite database does support foreign keys, and its foreign key syntax is similar to other databases. Here's a quick SQLite foreign key example. A SQLite foreign key example First, we define two database tables that don't have any foreign keys: -- -- salespeople -- CREATE TABLE salespeople ( id INTEGER PRIMARY KEY, first_name TEXT NOT NULL, last_name TEXT NOT NULL, commission_rate REAL NOT NULL ); -- -- customers -- CREATE TABLE customers ( id INTEGER PRIMARY KEY, company_name TEXT NOT NULL, street_address TEXT NOT NULL, city TEXT NOT NULL, state TEXT NOT NULL, zip TEXT NOT NULL ); Next, we define a SQLite table that has two foreign keys, one that relates our new orders table back to the customers table, and a second foreign key that relates the orders table back to the salespeople table:

Foreign Key Support. Small.

Foreign Key Support

Fast. Reliable.Choose any three. SQlite - Android - Foreign key syntax. Current community your communities Sign up or log in to customize your list. more stack exchange communities Stack Exchange sign up log in tour help careers 2.0 Stack Overflow Ask Question Take the 2-minute tour × Stack Overflow is a question and answer site for professional and enthusiast programmers.

SQlite - Android - Foreign key syntax

Android Tutorial 10 - Display Data from Database in List.