Androidで自動インクリメント行の値を取得したい
public void onCreate(SQLiteDatabase db) {
String CREATE_Order_Inner_TABLE = "CREATE TABLE " + TABLE_Order_Inner_Table + "("
+ Order_id + " AUTO_INCREMENT,"
+ Order_Date + " TEXT,"
+ Order_Time + " TEXT,"
+ Order_Total_Price + " TEXT"
+ ")";
db.execSQL(CREATE_Order_Inner_TABLE);
}
// Creating Tables
public void onCreate_previous_order(SQLiteDatabase db) {
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_Order_Inner_Table);
// Create tables again
onCreate(db);
}
/**
* Storing user details in database
* */
public int addInnerOrder(String Date, String time, String totalprice) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Order_Date, Date); // Name
values.put(Order_Time, time); // Email
values.put(Order_Total_Price,totalprice ); // Email
// Inserting Row
int id = (int) db.insert(TABLE_Order_Inner_Table, null, values);
db.close(); // Closing database connection
return id;
}
/**
* Getting user data from database
* */
public ArrayList<HashMap<String, Object>> getHistroyDetails(){
HashMap<String,String> user = new HashMap<String,String>();
String selectQuery = "SELECT * FROM " + TABLE_Order_Inner_Table;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// Move to first row
cursor.moveToFirst();
// if(cursor.getCount() > 0){
while(!cursor.isAfterLast())
{
HashMap<String, Object> map = new HashMap<String, Object>();
DataHolderHistroy obj=new DataHolderHistroy();
android.util.Log.i("cursor.getInt(cursor.getColumnIndex(Order_id))"," "+ cursor.getInt(cursor.getColumnIndex(Order_id)));
obj.setData(cursor.getInt(cursor.getColumnIndex(Order_id)),cursor.getString(cursor.getColumnIndex(Order_Date)),cursor.getString(cursor.getColumnIndex(Order_Total_Price)),cursor.getString(cursor.getColumnIndex(Order_Time)));
android.util.Log.i("cursor.getInt(22222222222"," "+ cursor.getString(cursor.getColumnIndex(Order_id)));
android.util.Log.i("cursor.gets(getStringgetString", cursor.getString(cursor.getColumnIndex(Order_Date)));
map.put(ITEMTITLEOrder, obj);
// adding HashList to ArrayList
OrdersList.add(map);
cursor.moveToNext();
// }
}
cursor.close();
db.close();
// return user
return OrdersList;
}
public class DataHolderHistroy
{
int Id;
String Date;
String totalPrice;
String time;
public void setData(int id,String date,String totalprice, String time)
{
this.Id=id;
this.Date=date;
this.totalPrice=totalprice;
this.time=time;
}
public int Get_id()
{return Id;}
public String GetDate()
{return Date;}
public String Getprice()
{return totalPrice;}
public String Gettime()
{return time;}
}
}
私のログキャット
10-01 17:03:49.820: I/cursor.getInt(cursor.getColumnIndex(Order_id))(23142): 0
10-01 17:03:49.820: I/cursor.getInt(22222222222(23142): null
10-01 17:03:49.820: I/cursor.gets(getStringgetString(23142): 01-Oct-2013
私の問題はこの時点です
DataHolderHistroy obj=new DataHolderHistroy();
android.util.Log.i("cursor.getInt(cursor.getColumnIndex(Order_id))"," "+ cursor.getInt(cursor.getColumnIndex(Order_id)));
obj.setData(cursor.getInt(cursor.getColumnIndex(Order_id)),
cursor.getString(cursor.getColumnIndex(Order_Date)),cursor.getString(cursor.getColumnIndex(Order_Total_Price)),cursor.getString(cursor.getColumnIndex(Order_Time)));
android.util.Log.i
("cursor.getInt(22222222222"," "+ cursor.getString(cursor.getColumnIndex(Order_id)));
android.util.Log.i("cursor.gets(getStringgetString", cursor.getString(cursor.getColumnIndex(Order_Date)));
私の主な問題は、自動インクリメントを持つ列の値を取得できないことです