sql - Android sqlite idimage can not be null -
i have problems when want add in db. error 19 idimage can not null, not understand why error, defined idimage auto increment.
thanks
import android.content.context; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import android.database.sqlite.sqlitedatabase.cursorfactory; public class basesqllite extends sqliteopenhelper{ private static final string create_bdd = "create table if not exists `t_image` (`idimage` integer primary key autoincremet,`name` varchar(20) not null ,`description` varchar(45) not null ,`rank` tinyint not null ,`date` varchar(45) not null ,primary key (`idimage`) )"; public basesqllite(context context, string name, cursorfactory factory, int version) { super(context, name, factory, version); } @override public void oncreate(sqlitedatabase db) { db.execsql(create_bdd); } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { db.execsql("drop table t_image ;"); oncreate(db); } } imagesbdd imagesbdd = new imagesbdd(context); simpledateformat timestampformat = new simpledateformat("yyyy-mm-dd-hh.mm.ss"); string photoname = "photo_" + timestampformat.format(new date()) +".jpg" ; string descri = myinputtext.gettext().tostring(); int rank = 1; string date = timestampformat.format(new date()); image image = new image(photoname,descri,rank,date); // open bd imagesbdd.open(); // insert of image imagesbdd.insertimage(image);
hello, answer still have problems.
there more information.
i changed sql request:
"create table if not exists t_image (idimage integer primary key autoincremet,name varchar(20) not null ,description varchar(45) not null ,rank tinyint not null ,date varchar(45) not null )";
there logcat error:
e/sqlitedatabase(19708): error inserting rank=1 date=2013-04-25-15.53.20 description=gun name=photo_2013-04-25-15.53.20.jpg e/sqlitedatabase(19708): android.database.sqlite.sqliteconstraintexception: t_image.idimage may not null (code 19)
there code insertion:
// insetion d'imahe public long insertimage(image image){ //création d'un contentvalues contentvalues values = new contentvalues(); //on lui ajoute une valeur associé à une clé (qui est le nom de la colonne dans laquelle on veut mettre la valeur) values.put(col_name, image.getname()); values.put(col_description, image.getdescription()); values.put(col_rank, image.getrank()); values.put(col_date, image.getdate()); //on insère l'objet dans la bdd via le contentvalues return bdd.insert(table_images, null, values); }
i think error in syntax.
private static final string create_bdd = " create table if not exists `t_image` (`idimage` integer primary key autoincremet,`name` varchar(20) not null ,`description` varchar(45) not null ,`rank` tinyint not null ,`date` varchar(45) not null ,primary key (`idimage`) )";
this should be
private static final string create_bdd = "create table if not exists t_image (idimage integer primary key autoincremet,name varchar(20) not null ,description varchar(45) not null ,rank tinyint not null ,date varchar(45) not null ,primary key (idimage) )";
quets not come table name , column names.
just try it.
i hope you.