I'm creating my database with class sqliteOpenHelper
, passing DB creation by String
through StringBuilder
.
The problem is that you are only creating the first table, and then you do not create the next table, in which case I am creating the city first. If I invested putting the consumption first and the others in sequence, it would create consumption and would not create the next, ie it always creates the first table only.
I thought it might be because of character limit, so I used str.ensureCapacity(10000);
but no success.
public void onCreate(SQLiteDatabase db) {
StringBuilder str = new StringBuilder();
str.append("CREATE TABLE cidade (");
str.append("_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, ");
str.append("nome VARCHAR(20), ");
str.append("estado VARCHAR(2), ");
str.append("vlaguaI DECIMAL, ");
str.append("vlaguaII DECIMAL, ");
str.append("vlaguaIII DECIMAL, ");
str.append("vlinicial_faixa_consumoI INTEGER, ");
str.append("vlfinal_faixa_consumoI INTEGER, ");
str.append("vlinicial_faixa_consumoII INTEGER, ");
str.append("vlfinal_faixa_consumoII INTEGER, ");
str.append("vlinicial_faixa_consumoIII INTEGER, ");
str.append("vlfinal_faixa_consumoIII INTEGER, ");
str.append("vl_esgoto DECIMAL, ");
str.append("vl_taxa_afastamento DECIMAL); ");
str.append("CREATE TABLE consumo (");
str.append("_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, ");
str.append("dt_leitura DATE), ");
str.append("registro INTEGER, ");
str.append("vl_consumo DECIMAL); ");
str.append("CREATE TABLE configuracao (");
str.append("_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, ");
str.append("id_cidade INTEGER NOT NULL, ");
str.append("hidrometro INTEGER, ");
str.append("CONSTRAINT fk_configuracao ");
str.append("FOREIGN KEY(id_cidade) ");
str.append("REFERENCES cidade(_id)); ");
str.append("CREATE INDEX configuracao.fk_configuracao_idx ON configuracao(id_cidade); ");
db.execSQL(str.toString());