lundi 30 novembre 2015

Android: table has no column named 'columnname'

I have en error: android.database.sqlite.SQLiteException: table aerzte has no column named _vorname

But my table has the column _vorname. I can not find the error, please help me. Here is the code:

private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "data.db"; 
private static final String TABLE_Aerzte = "aerzte";
private static final String COLUMN_ID = "_id";
private static final String COLUMN_Name = "_name";
private static final String COLUMN_Passwort = "_passwort";
private static final String COLUMN_Vorname = "_vorname";

//second table
private static final String TABLE_Patienten = "patienten";
private static final String COLUMN_patID = "_id";
private static final String COLUMN_patName = "_name";
private static final String COLUMN_patVorname = "_vorname";
private static final String COLUMN_patSVNR = "_svnr";



//third table
private static final String TABLE_Werte = "werte";
private static final String COLUMN_wertID = "_id";
private static final String COLUMN_wertpatName = "_name"; //foreign key -> patient (1:n) beziehung
private static final String COLUMN_wertDatzeit = "_datzeit";
private static final String COLUMN_wertTemperatur = "_temperatur";
private static final String COLUMN_wertMessort = "_messort";

 public MyDBHandler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
    super(context, DATABASE_NAME, factory, DATABASE_VERSION);
     }


   //create tables:
       @Override
public void onCreate(SQLiteDatabase db) {
    //tabelle arzt
    String query = "CREATE TABLE  "+TABLE_Aerzte+"("+COLUMN_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+COLUMN_Passwort+" TEXT, "+COLUMN_Name+ " TEXT, " +COLUMN_Vorname+ "TEXT " + ");";
    db.execSQL(query);

    //tabelle patient
    String query2 = "CREATE TABLE  "+TABLE_Patienten+"("+COLUMN_patID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+COLUMN_patName+" TEXT,"+COLUMN_patVorname+" TEXT, "+COLUMN_patSVNR+" LONG" + ");";
    db.execSQL(query2);

    //tabelle wert
    String query3 = "CREATE TABLE  "+TABLE_Werte+"("+COLUMN_wertID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+COLUMN_wertMessort+" TEXT, "+COLUMN_wertTemperatur+ " INTEGER, "+COLUMN_wertDatzeit+" DATETIME, "+COLUMN_wertpatName+" TEXT, FOREIGN KEY" + ");";
    db.execSQL(query3);

}



//insert
 public void registerPhysician(Fieberwerte fieberwerte) { // public void registerPhysician(etname, etpass, etvorname)

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    //values.put(COLUMN_ID, 1);
    values.put(COLUMN_Passwort, fieberwerte.getPasswort());
    values.put(COLUMN_Name, fieberwerte.getName());
    values.put(COLUMN_Vorname, fieberwerte.getVorname());
    //db.insert(TABLE_Aerzte, null, values);
    db.insertWithOnConflict(TABLE_Aerzte, null, values, SQLiteDatabase.CONFLICT_REPLACE);
    //db.close();
}

I hope you guys can help me to fix this error. I checked the code several times but I do not find any error :-(

Sqlite for client server program

I am writing a simple client server program in QT and now i want every message that client send to server save in "SQLite" in server side. How can i do it? Could you please help me? Thanks

Android Sqlite Insert syntax error

I can't seem to find out what exactly I did wrong here. Seem to be getting a syntax error in my insert command inside the addCheck method.

Android SQLite Insert Error (Syntax error code 1)

I've added my database code:

public void createNewTable(int _id, boolean _emp){
    SQLiteDatabase db = this.getWritableDatabase();
        Log.v("Database", "Adding Check in table: " + _id);
        String CREATE_TABLE = " CREATE TABLE " + Integer.toString(_id) + "("
                + KEY_DATE + " TEXT," + KEY_TIME_IN + " TEXT," + KEY_TIME_OUT + " TEXT,"
                + KEY_LATITUDE_IN + " REAL," + KEY_LONGITUDE_IN + " REAL," + KEY_LATITUDE_OUT + " REAL,"
                + KEY_LONGITUDE_OUT + " REAL" + ")";
        db.execSQL(CREATE_TABLE);}
public void addCheck(Check check){
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    //values.put(KEY_ID, user.getId());
    values.put(KEY_DATE, check.getDate());
    values.put(KEY_TIME_IN, check.getTimeIn());
    values.put(KEY_TIME_OUT, check.getTimeOut());
    values.put(KEY_LATITUDE_IN, check.getLocIn().getLatitude());
    values.put(KEY_LONGITUDE_IN, check.getLocIn().getLongitude());
    values.put(KEY_LATITUDE_OUT, check.getLocOut().getLatitude());
    values.put(KEY_LONGITUDE_OUT, check.getLocOut().getLongitude());
    // Inserting Row
    db.insert(Integer.toString(check.getId()), null, values);
    db.close();
}

The check class is:

public class Check {
int _id;
String _date;
String _timeIn;
String _timeOut;
Location _locIn;
Location _locOut;

public Check(){}
public Check(int id, String date, String t_in, Location l_in){
    this._id=id;
    this._date=date;
    this._timeIn=t_in;
    this._locIn=l_in;
    this._locOut= new Location("");
    this._timeOut="0";
}

public Check(int id, String date, String t_in, String t_out, Location l_in, Location l_out){
    this._id=id;
    this._date=date;
    this._timeIn=t_in;
    this._timeOut=t_out;
    this._locIn=l_in;
    this._locOut=l_out;
}

public int getId(){return this._id;}
public String getDate(){return this._date;}
public String getTimeIn(){return this._timeIn;}
public String getTimeOut(){return this._timeOut;}
public Location getLocIn(){return this._locIn;}
public Location getLocOut(){return this._locOut;}

public void setId(int id){this._id=id;}
public void setDate(String date){this._date=date;}
public void setTimeIn(String t_in){this._timeIn=t_in;}
public void setTimeOut(String t_out){this._timeOut=t_out;}
public void setLocIn(Location l_in){this._locIn=l_in;}
public void setLocOut(Location l_out){this._locOut=l_out;}}

Finally my logcat error is:

E/SQLiteDatabase﹕ Error inserting latCheckIn=-33.85147605 longCheckOut=0.0 latCheckOut=0.0 timeCheckIn=11:53:49 timeCheckOut=0 longCheckIn=18.647984 date=2015-11-30
android.database.sqlite.SQLiteException: near "1": syntax error (code 1): , while compiling: INSERT INTO 1(latCheckIn,longCheckOut,latCheckOut,timeCheckIn,timeCheckOut,longCheckIn,date) VALUES (?,?,?,?,?,?,?)

I know this is just a syntax error, but I really can't find it. Any help would be appreciated.

Thanks

SQLlite: strange "Abort due to constraint violation"

I'm trying to rename a column of a table. I have a lot of tables with the word "couleur" and I renamed "manually" to "bulle".

I've successfully renamed main_groupecouleurs to main_groupebulles. Now i'm working on main_groupe. I'm trying to rename groupe_couleurs_id to groupe_bulles_id

The SQL is quite self-explaining:

BEGIN TRANSACTION;
DROP INDEX main_groupe_fc5cee5b;
CREATE TABLE main_groupe7e12
(
    id INTEGER PRIMARY KEY NOT NULL,
    description TEXT NOT NULL,
    exemple TEXT,
    groupe_bulles_id INTEGER DEFAULT NULL,
    reference TEXT,
    FOREIGN KEY (groupe_bulles_id) REFERENCES main_groupebulles(id)
        DEFERRABLE INITIALLY DEFERRED
);
CREATE UNIQUE INDEX main_groupe_fc5cee5b ON main_groupe7e12 (groupe_bulles_id);
INSERT INTO main_groupe7e12(id, description, exemple, groupe_bulles_id, reference)
                     SELECT id, description, exemple, groupe_couleurs_id, reference
                     FROM main_groupe;
DROP TABLE main_groupe;
ALTER TABLE main_groupe7e12 RENAME TO main_groupe;
COMMIT;

When I run it, I get:

[SQLITE_CONSTRAINT]  Abort due to constraint violation
    (UNIQUE constraint failed: main_groupe7e12.groupe_bulles_id)

This means (I think I'm wrong here but I dont know what I'm missing) that it tries to insert some groupe_couleurs_id that are not in the referring table (= main_groupebulles). Thus I tried to see in the original table the problem:

SELECT * FROM main_groupe WHERE groupe_couleurs_id NOT IN (
    SELECT id FROM main_groupebulles
);

I got no rows! What am I missing?

learning sqlite database for Android Studio 1.4.1

I do not understand the database. Please introduce me to a very simple site and mental training.I want to bring it to Android Studio 1.4.1 Studio API23 thank

relational database tool with table relationships and fields in a single view

I use Ubuntu 14.04 OS. I have a database designed in sqlite. I want to see table relationships and fields in a single page view. I tried SQlite database browser and Firefox SQLite Manager add-on. Both of them works at the same way and don't show relationships and table fields in a single page view. Any tool for mysql also will be acceptable. What is your suggestion?

Regards

apache cordova using sqlite can't wait to return

     function outDb(outData) {
         var temp;
         var db = window.sqlitePlugin.openDatabase({ name: "test" });
         db.executeSql("SELECT " + outData + " FROM test", [], function (res) {
             switch (outData) {
                       case "goal": temp = res.rows.item(0).GOAL;
                     break;
                 case "curDate":  temp = res.rows.item(0).CURDATE;
                     break;
                 case "Day1":  temp = res.rows.item(0).DAY1;
                     break;
                 case "Day2":  temp = res.rows.item(0).DAY2;
                     break;
                 case "Day3":  temp = res.rows.item(0).DAY3;
                     break;
                 default: temp = "is default";
             }
         });
         return temp;
     }

I want to save data into myData;

var myData = outDb("goal");

but it is not working. because return faster than variable save.

What can I do?