⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbadapter.java

📁 android开发入门与实践源代码
💻 JAVA
字号:
package com.iceskysl.iTracks;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DbAdapter {
	private static final String TAG = "DbAdapter";

	private static final String DATABASE_NAME = "iTracks.db";
	private static final int DATABASE_VERSION = 1;
	
	public class DatabaseHelper extends SQLiteOpenHelper {
		public DatabaseHelper(Context context) {
			super(context, DATABASE_NAME, null, DATABASE_VERSION);
		}

		@Override
		public void onCreate(SQLiteDatabase db) {
			String tracks_sql = "CREATE TABLE " + TrackDbAdapter.TABLE_NAME + " (" 
			+ TrackDbAdapter.ID	+ " INTEGER primary key autoincrement, " 
			+ TrackDbAdapter.NAME	+ " text not null, " 
			+ TrackDbAdapter.DESC + " text ," 
			+ TrackDbAdapter.DIST + " LONG ," 
			+ TrackDbAdapter.TRACKEDTIME + " LONG ," 
			+ TrackDbAdapter.LOCATE_COUNT + " INTEGER, " 
			+ TrackDbAdapter.CREATED + " text, " 
			+ TrackDbAdapter.AVGSPEED + " LONG, " 
			+ TrackDbAdapter.MAXSPEED + " LONG ," 
			+ TrackDbAdapter.UPDATED + " text " 
			+ ");";
			Log.i(TAG, tracks_sql);
			db.execSQL(tracks_sql);
			
			String locats_sql = "CREATE TABLE " + LocateDbAdapter.TABLE_NAME + " (" 
			+ LocateDbAdapter.ID	+ " INTEGER primary key autoincrement, " 
			+ LocateDbAdapter.TRACKID	+ " INTEGER not null, " 
			+ LocateDbAdapter.LON + " DOUBLE ," 
			+ LocateDbAdapter.LAT + " DOUBLE ," 
			+ LocateDbAdapter.ALT + " DOUBLE ," 
			+ LocateDbAdapter.CREATED + " text " 
			+ ");";	
			Log.i(TAG, locats_sql);
			db.execSQL(locats_sql);

		}

		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			db.execSQL("DROP TABLE IF EXISTS " + LocateDbAdapter.TABLE_NAME + ";");
			db.execSQL("DROP TABLE IF EXISTS " + TrackDbAdapter.TABLE_NAME + ";");
			onCreate(db);
		}

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -