android-sqlite(浅解析)

*个人目前从事的是我喜欢的工作,唯一的不顺心的是自己的提升很有限,提升的很艰难。不过,
我对自己的成长很有信心,终有一天会从上层到底层彻底的打通的,大到框架,小到底层源码。*

android的数据存储方式有以下5种。

1 使用SharedPreferences存储数据

2 文件存储数据      

3 SQLite数据库存储数据

4 使用ContentProvider存储数据

5 网络存储数据

其中SharedPreference和文件、数据库存储算比较常见的存储方式。

今天,我们看的是sqlite,android设备内置数据库。

android.database.sqlite

这里写图片描述

Some device manufacturers include different versions of SQLite on their devices. There are two ways to programmatically determine the version number.
(大意:不同设备生产商内置的数据库版本不同,使用两种方法可以查看数据库版本)

If available, use the sqlite3 tool, for example: adb -e shell sqlite3 –version.
(主要的意思推荐我们使用sqlite3工具查看版本)

创建和查询内存数据库示例代码:

  String query = "select sqlite_version() AS sqlite_version";
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(":memory:", null);
    Cursor cursor = db.rawQuery(query, null);
    String sqliteVersion = "";
    if (cursor.moveToNext()) {
        sqliteVersion = cursor.getString(0);
    }
SQLiteDatabase

public final class SQLiteDatabase extends SQLiteClosable 


java.lang.Object
   ↳    android.database.sqlite.SQLiteClosable
   ↳    android.database.sqlite.SQLiteDatabase

Database names must be unique within an application, not across all applications.
(大意:数据库名称必须在应用程序中是唯一的,而不是在所有应用程序。)

create(创建)

SQLiteDatabase create (SQLiteDatabase.CursorFactory factory)

delete(删除)

int delete (String table, String whereClause, String[] whereArgs)

deleteDatabase(删除数据库)

boolean deleteDatabase (File file)

Parameters
file File: The database file path.
Returns
boolean True if the database was successfully deleted.

execSQL

void execSQL (String sql)

getPath

String getPath ()
Gets the path to the database file.
(大意:获取数据库文件路径。)
Returns
String The path to the database file.

getVersion

int getVersion ()
Gets the database version.

Returns
int the database version

insert(插入)

long insert (String table,
String nullColumnHack,
ContentValues values)

query(查询)

Cursor query (boolean distinct,
String table,
String[] columns,
String selection,
String[] selectionArgs,
String groupBy,
String having,
String orderBy,
String limit)

update(更新)

int update (String table,
ContentValues values,
String whereClause,
String[] whereArgs)

好了,下期:

SQLiteOpenHelper

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值