2
I am creating my database with the class sqliteOpenHelper, passing the creation of DB by String through the StringBuilder.
The problem is, it’s just creating the first table, and then it doesn’t create the next one, in which case I’m creating the city first. If I reversed putting consumption by first and the others in sequence, it would create consumption and not create the next, ie it always creates the first table only.
I thought it might be because of the character limit, so I used the str.ensureCapacity(10000); but without 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());
Friends, thank you all so much for the answers, really in the str.append("dt_reading DATE), ") excerpt; it was incorrect, because I was doing tests, commenting on some lines of the table thinking that it was because of the excess of string I wasn’t creating, but I had already corrected and did not change the post, sorry. Regarding the resolution of my problem, I chose to use Victor Stafusa’s, which worked correctly. Thank you very much. hug
– Geovani Rafael Sório