2
I included a new column in a table. I reinstalled the application and at the time of saving the data there is a message saying that there is a pathImage column, in my case in the clients table. I read some things about it and I was advised to install the application again and it still hasn’t solved. I’m trying to make a ALTER TABLE
but maybe I’m doing it wrong. I ask for help. Thank you.
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import static br.gestaoBd.Login.db;
import static java.lang.Integer.TYPE;
public class BancoDados extends SQLiteOpenHelper {
public BancoDados(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
EstruturaBanco.criarTabelas();
}
@Override
public void onUpgrade(SQLiteDatabase sqld, int i, int i1) {
db.execSQL("ALTER TABLE [clientes] ADD COLUMN [pathImagem2] VARCHAR2(125) NOT NULL ");
}
}
Bank structure
import br.gestaoBd.Login;
public class EstruturaBanco {
public static void criarTabelas() {
System.out.println("Criando as tabelas...");
StringBuilder sb = new StringBuilder();
sb.append(" CREATE TABLE IF NOT EXISTS [clientes] (");
sb.append(" [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,");
sb.append(" [nome] VARCHAR2(70) NOT NULL,");
sb.append(" [email] VARCHAR2(70) NOT NULL,");
sb.append(" [telefone] VARCHAR2(30) NOT NULL,");
sb.append(" [endereco] VARCHAR2(70) NOT NULL,");
sb.append(" [rg] VARCHAR2(30) NOT NULL,");
sb.append(" [cpf] VARCHAR2(30) NOT NULL,");
sb.append(" [pathImagem2] VARCHAR2(125) NOT NULL);");
Login.db.execSQL(sb.toString());
......................