POP Article V2.0 设为主页
收藏本站
首 页交流论坛留 言
您现在的位置:首 页 >> 开发文档 >> 官方文档汉化 >> 查看文章
android.database.sqlite 文档翻译(2)
作者:tamsyn  来源:www.sqlite.com.cn  时间:2008-1-10  【 字体: 】 〖 双击滚屏 〗

从接口android.database.sqlite.SQLiteClosable 继承的方法

close

 void 

close()

详细信息

公有方法

public void close()

关闭数据库

public SQLiteStatement compileStatement(String sql)

编制一条sql语句成为一个可重复使用的预编译的声明对象,参量是相同的execSQL(String),可以在语句中使用字符”?” 在每次执行声明对象时通过bindString(int, String) bindLong(int, long)再填写这些值。声明对象返回结果集可能不会大于1x1

参数

sql

原始SQL语句,可以包含字符”?”代替在执行是才能获知的值。

返回

·                          预编译对象。

抛出异常

SQLException

android.database.SQLException

public static SQLiteDatabase create(CursorFactory factory)

创建一个内存支持SQLite数据库。在该数据库关闭时将被销毁其内容。

 

参数

factory

可选,提供在执行查询时获得一个游标实例的工厂类。

返回

·                          SQLite数据库对象,当不能被创建时返回空。

public static SQLiteDatabase create(File file, int version, CursorFactory factory)

创建一个新的sqlite数据库并打开。

参数

file

需要建立的数据库文件

version

数据库版本标签

factory

可选,提供在执行查询时获得一个游标实例的工厂类。

返回

·                          SQLite数据库对象,当不能被创建时返回空。

public static SQLiteDatabase create(String path, int version, CursorFactory factory)

创建一个新的sqlite数据库并打开。

参数

path

需要建立的数据库的路径

version

数据库版本标签

factory

可选,提供在执行查询时获得一个游标实例的工厂类。

返回

·                          SQLite数据库对象,当不能被创建时返回空。

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

提供便利的方法删除数据库中一条记录(row)

参数

table

需要删除记录的表

whereClause

可选,通过Where字句进行条件删除,为空则删除全部记录。

返回

·                          所影响的行数。在whereClususe条件不合法时返回 0 . To remove all rows and get a count pass "1" as the whereClause.

public void execSQL(String sql)

执行一条非查询SQL语句。例如,创建表,删除、添加记录等等。但不支持多条语句之间用字符”;”分隔。

抛出异常

SQLException

sql语句字符串无效则抛出SQLException

public long getMaximumSize()

获取数据库容量可增长到的上限值。

返回

·                          一个新的数据库容量上限值。

public long getPageSize()

获取数据库页大小值。

返回

·                          一个新的数据库容量上限值。

public final String getPath()

获取数据库文件路径。

Returns

·                          数据库文件的路径。

public Map getSyncedTables()

public int getVersion()

获取数据库版本。

返回

·                          数据库版本标示或者当发生一个错误事件是返回 -1

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

提供便利的方法在数据库中新增一条记录(row)

参数

table

需要新增记录的表

nullColumnHack

SQL 不允许增加一条完全空的记录,所以如果初始值为空则将明确分配一个null值给该列。

values

记录中各字段初始值的MapMap的键是字段的名称,值为该字段的值。

返回

·                          新插入行的行号,如果发生错误则返回 -1

public void markTableSyncable(String table, String deletedTable)

标记该表可同步.当一个更新发生在该表时,_sync_dirty(同步的脏数据?)字段将会被设置以确保有适当的同步运作。

参数

table

需要被标记为可同步的表

deletedTable

The deleted table that corresponds to the syncable table

public void markTableSyncable(String table, String foreignKey, String updateTable)

Mark this table as syncable, with the _sync_dirty residing in another table. When an update occurs in this table the _sync_dirty field of the row in updateTable with the _id in foreignKey will be set to ensure proper syncing operation.

Parameters

table

an update on this table will trigger a sync time removal

foreignKey

this is the column in table whose value is an _id in updateTable

updateTable

this is the table that will have its _sync_dirty

public static SQLiteDatabase open(File file, CursorFactory factory)

从一个文件打开一个SQLite数据库。

参数

file

包含数据库的文件

factory

可选,提供在执行查询时获得一个游标实例的工厂类。

返回

·                          SQLite数据库对象, 当数据库不存在时返回空。

public static SQLiteDatabase open(String path, CursorFactory factory)

从一个文件的路径打开一个SQLite数据库。

参数

path

包含数据库的文件的路径

factory

可选,提供在执行查询时获得一个游标实例的工厂类。

返回

·                          SQLite数据库对象, 当数据库不存在时返回空。

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

查询给定的url ,返回一个Cursor的结果集。

参数

distinct

当为true时,结果中每条记录唯一。否则,不唯一。

table

需要进行查询的表

columns

需要返回值的字段的集合。如果为空则返回所有字段,这是为了阻止从存储器上预读取并不是准备使用的数据。A list of which columns to return. Passing null will return all columns, which is discouraged to prevent reading data from storage that isn't going to be used.

selection

返回记录过滤器,,如果为空则返回指定表中的所有记录。A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given table.

selectionArgs

selection中可以使用字符”?”作为顺序占位符。所有的顺序占位符会被selectionArgs中的值替换,这些值在selection中以字符串的形式出现。You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings.

groupBy

记录组合过滤器,,如果为空则所有记录不会被分组。A filter declaring how to group rows, formatted as an SQL GROUP BY clause (excluding the GROUP BY itself). Passing null will cause the rows to not be grouped.

having

A filter declare which row groups to include in the cursor, if row grouping is being used, formatted as an SQL HAVING clause (excluding the HAVING itself). Passing null will cause all row groups to be included, and is required when row grouping is not being used.

orderBy

How to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered.

Returns

·                          A Cursor object, which is positioned before the first entry

See Also

·                          Cursor

public Cursor query(String sql, String[] selectionArgs)

Runs the provided SQL and returns a cursor over the result set.

Parameters

sql

the SQL query. The SQL string must not be ; terminated

selectionArgs

You may include ?s in where clause in the query, which will be replaced by the values from selectionArgs. The values will be bound as Strings.

Returns

·                          A Cursor object, which is positioned before the first entry

public Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy)

Query the given table, returning a Cursor over the result set.

Parameters