在 2013年5月1日星期三,Παύλος-Πέτρος Τουρνάρης 写道:

> Make your key_id autoincrement and it should be fine!
>
>
> On 1 May 2013 16:49, Marty Ballard <marty...@gmail.com> wrote:
>
> It appears to me that you are always inserting key_id = 0, therefore this
> would be a duplicate insert.  I believe you should be increasing this by +1
> for each insert.
>
>
> On Friday, April 26, 2013 11:20:20 AM UTC-5, Nathan wrote:
>
> I can not figure out what is happening here for the life of me. Everything
> was working fine. I went to bed one night and came back the next and now my
> app will not read or write to my db and gives me no errors. Please help any
> advice would be great.
>
>
> My DB Handler:
> ==============================**==============================**
> ==============================**=====================
> import android.content.ContentValues;
> import android.content.Context;
> import android.database.Cursor;
> import android.database.sqlite.**SQLiteDatabase;
> import android.database.sqlite.**SQLiteOpenHelper;
>
> public class DatabaseHandler extends SQLiteOpenHelper {
>     // All Static variables
>     // Database Version
>     private static final int DATABASE_VERSION = 1;
>
>     // Database Name
>     private static final String DATABASE_NAME = "GP";
>
>     // Contacts table name
>     private static final String TABLE_VERSION = "GPVersion";
>
>
>     // Contacts Table Columns names
>     private static final String KEY_ID = "id";
>     private static final String KEY_VERSION = "name";
>
>  public DatabaseHandler(Context context) {
>         super(context, DATABASE_NAME, null, DATABASE_VERSION);
>     }
>
> @Override
>  public void onCreate(SQLiteDatabase db) {
> // TODO Auto-generated method stub
>         String CREATE_VERSION_TABLE = "CREATE TABLE IF NOT EXISTS " +
> TABLE_VERSION + "("
>                 + KEY_ID + " INTEGER PRIMARY KEY," + KEY_VERSION + " TEXT"
> + ")";
>         db.execSQL(CREATE_VERSION_**TABLE);
> }
>
> @Override
> public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
> // TODO Auto-generated method stub
>         //db.execSQL("DROP TABLE IF EXISTS " + TABLE_VERSION);
>
>         // Create tables again
>         //onCreate(db);
> }
>
>   // Adding new version
>     void addGPVersion(String version) {
>         SQLiteDatabase db = this.getWritableDatabase();
>
>         ContentValues values = new ContentValues();
>         values.put(KEY_ID, "0"); // Pair
>         values.put(KEY_VERSION, version); // Pair
>
>         // Inserting Row
>         db.insert(TABLE_VERSION, null, values);
>         db.close(); // Closing database connection
>     }
>
>
>     // Getting students Count
>     public String getGPVersion() {
>     SQLiteDatabase db = this.getReadableDatabase();
>     String q="SELECT " + KEY_VERSION + " FROM " + TABLE_VERSION + " WHERE
> " + KEY_ID + "='0'";
>     String z;
>
>     Cursor cursor = db.rawQuery(q,null);
>     if (cursor != null && cursor.getCount()>0) {
>     cursor.moveToFirst();
>     z=cursor.getString(0);
>
>
> --
> *Παύλος-Πέτρος Τουρνάρης*
> *Android  & Software Developer*
>
>    - *http://goo.gl/TsJ8u*
>    - *http://acschedule.org*
>
>  --
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to 
> android-developers@googlegroups.com<javascript:_e({}, 'cvml', 
> 'android-developers@googlegroups.com');>
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com <javascript:_e({},
> 'cvml', 'android-developers%2bunsubscr...@googlegroups.com');>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to android-developers+unsubscr...@googlegroups.com<javascript:_e({}, 
> 'cvml',
> 'android-developers%2bunsubscr...@googlegroups.com');>.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to