package com.signway.log;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class LogSQL {
private static final String TAG
="LogSQL";
private static final String DB_NAME
="Droid.db";
private static final int DB_VERSION =1;
private static final String TABLE_PLAY
="table_play";
private static final String
KEY_FID_PLAY="_id";
private static final String
KEY_PID_PLAY="pid";
private static final String
KEY_NUM_PLAY="num";
private static final String
KEY_TIME_PLAY="time";
private static final String PLAY_CREATE="CREATE
TABLE "
+ TABLE_PLAY
+ " ("
+
KEY_FID_PLAY +
" TEXT
PRIMARY KEY,"
+
KEY_PID_PLAY + " TEXT,"
+
KEY_NUM_PLAY + " INTERGER,"
+
KEY_TIME_PLAY + " INTERGER)";
private Context context;
private SQLiteDatabase database;
private DatabaseHelper databaseHelper;
public LogSQL(Context context){
this.context = context;
}
public void open(){
databaseHelper = new
DatabaseHelper(context);
database =
databaseHelper.getWritableDatabase();
}
public void close(){
databaseHelper.close();
}
public void insertPlayData(String fid,String
pid,int num,int time){
ContentValues values = new
ContentValues();
values.put(KEY_FID_PLAY,
fid);
values.put(KEY_PID_PLAY,
pid);
values.put(KEY_NUM_PLAY,
num);
values.put(KEY_TIME_PLAY,
time);
database.insert(TABLE_PLAY,
KEY_FID_PLAY, values);
}
public void getPlayDataPid(String fid){
Cursor cursor =
database.query(true, TABLE_PLAY, new
String[]{KEY_FID_PLAY,KEY_PID_PLAY},
KEY_FID_PLAY+ "="+fid, null,
null, null, null, null);
//注意“=”没有两遍没有空格,我写了空格老是报错找不到_id
if(cursor.moveToFirst()){
int index =
cursor.getColumnIndex(KEY_PID_PLAY);
String pid =
cursor.getString(index);
Log.d(TAG,
"msg pid:"+pid);
}
Log.d(TAG, "msg pid:
null");
}
public class DatabaseHelper extends
SQLiteOpenHelper{
public
DatabaseHelper(Context context) {
super(context,
DB_NAME, null, DB_VERSION);
// TODO
Auto-generated constructor stub
}
@Override
public void
onCreate(SQLiteDatabase db) {
// TODO
Auto-generated method stub
db.execSQL(PLAY_CREATE);
}
@Override
public void
onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
// TODO
Auto-generated method stub
db.execSQL("");
onCreate(db);
}
}
}