티스토리 뷰
//-----------------------------
public class LocationReaderDbHelper extends SQLiteOpenHelper {
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "LocationReader.db";
public LocationReaderDbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public LocationReaderDbHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(LocationReaderContract.SQL_CREATE_ENTRIES);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(LocationReaderContract.SQL_DELETE_ENTRIES);
onCreate(db);
}
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onUpgrade(db, oldVersion, newVersion);
}
}
//-------------------------------------
public final class LocationReaderContract {
private LocationReaderContract(){}
private static final String TEXT_TYPE = " TEXT";
private static final String COMMA_SEP = ",";
public static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + FeedEntry.TABLE_NAME + " (" +
FeedEntry._ID + " INTEGER PRIMARY KEY," +
FeedEntry.COLUMN_NAME_TARGET + TEXT_TYPE + COMMA_SEP +
FeedEntry.COLUMN_NAME_SEQUENCE + TEXT_TYPE + COMMA_SEP +
FeedEntry.COLUMN_NAME_TYPE + TEXT_TYPE + COMMA_SEP +
FeedEntry.COLUMN_NAME_CREATEON + TEXT_TYPE + COMMA_SEP +
FeedEntry.COLUMN_NAME_LONGITUDE + TEXT_TYPE + COMMA_SEP +
FeedEntry.COLUMN_NAME_LATITUDE + TEXT_TYPE + " )";
public static final String SQL_DELETE_ENTRIES =
"DROP TABLE IF EXISTS " + FeedEntry.TABLE_NAME;
/* Inner class that defines the table contents */
public static class FeedEntry implements BaseColumns {
public static final String TABLE_NAME = "device";
public static final String COLUMN_NAME_TARGET = "target"; //v100,t100
public static final String COLUMN_NAME_SEQUENCE = "sequence";
public static final String COLUMN_NAME_TYPE = "type"; //Type of Location WiFi, GPSKT, Cell
public static final String COLUMN_NAME_CREATEON = "createon";
public static final String COLUMN_NAME_LONGITUDE = "longitude";
public static final String COLUMN_NAME_LATITUDE = "latitude";
}
}
//--------------------------------------------------------------------------
LocationReaderDbHelper mDbHelper = new LocationReaderDbHelper(this);
// Gets the data repository in write mode
SQLiteDatabase db = mDbHelper.getWritableDatabase();
// Create a new map of values, where column names are the keys
ContentValues values = new ContentValues();
values.put(FeedEntry.COLUMN_NAME_TARGET, "1062");
values.put(FeedEntry.COLUMN_NAME_SEQUENCE, "7");
values.put(FeedEntry.COLUMN_NAME_CREATEON, "7");
values.put(FeedEntry.COLUMN_NAME_LONGITUDE, "37");
values.put(FeedEntry.COLUMN_NAME_LATITUDE, "150");
// Insert the new row, returning the primary key value of the new row
long newRowId = db.insert(FeedEntry.TABLE_NAME, null, values);
Log.d(TAG,newRowId+"");
db = mDbHelper.getReadableDatabase();
String[] projection = {
FeedEntry._ID,
FeedEntry.COLUMN_NAME_TARGET,
FeedEntry.COLUMN_NAME_SEQUENCE,
FeedEntry.COLUMN_NAME_LONGITUDE,
FeedEntry.COLUMN_NAME_LATITUDE,
FeedEntry.COLUMN_NAME_CREATEON
};
String selection = FeedEntry.COLUMN_NAME_TARGET + " = ?";
String[] selectionArgs = { "1062" };
String sortOrder =
FeedEntry.COLUMN_NAME_SEQUENCE + " DESC";
Cursor c = db.query(
FeedEntry.TABLE_NAME, // The table to query
projection, // The columns to return
selection, // The columns for the WHERE clause
selectionArgs, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
sortOrder // The sort order
);
while(c.moveToNext()){
Log.d(TAG,"id:"+c.getLong(c.getColumnIndexOrThrow(FeedEntry._ID))
+""
+c.getString(c.getColumnIndex(FeedEntry.COLUMN_NAME_TARGET))
+c.getString(c.getColumnIndex(FeedEntry.COLUMN_NAME_SEQUENCE))
+c.getString(c.getColumnIndex(FeedEntry.COLUMN_NAME_LATITUDE))
+c.getString(c.getColumnIndex(FeedEntry.COLUMN_NAME_LONGITUDE))
+c.getString(c.getColumnIndex(FeedEntry.COLUMN_NAME_CREATEON))
);
}
//--------------------------------------------------------------------------
'JAVA' 카테고리의 다른 글
apache httpclient proxy authentication id password (0) | 2017.09.07 |
---|---|
ORACLE 프로시져생성, 권한, Synonym (0) | 2017.09.05 |
전자정부프레임워크 log4j2 maven 설정 (0) | 2017.05.23 |
안드로이드 속도 문제, Optimize Your Build Speed (0) | 2017.05.08 |
Java Computer vision Open source Java Library (0) | 2017.04.18 |
- Total
- Today
- Yesterday
- qwebview
- 사용법
- 리눅스
- 안드로이드 화면 밝기 조절
- SW대회
- 프로젝트관리전문가
- 자유한국당
- .svn
- 디지털서명
- websocket
- 서버주소
- setup.py
- ORACLE 프로시져생성
- 명령어
- Python
- stamp
- 코드스쿨
- 관련사이트
- Android
- signtool
- 프로그래밍대회
- 소프트웨어대회
- 타임스탬프
- 파이썬
- 파이썬프레임워크
- PyQt
- IT-PMP
- 온라인저지
- WSS
- 더불어 민주당
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |