mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +08:00
Suggest users to use PRAGMA function instead
This commit is contained in:
parent
9c00dd01a2
commit
6ce5c9ddcc
@ -161,6 +161,9 @@ impl Connection {
|
|||||||
///
|
///
|
||||||
/// Some pragmas will return multiple rows/values which cannot be retrieved
|
/// Some pragmas will return multiple rows/values which cannot be retrieved
|
||||||
/// with this method.
|
/// with this method.
|
||||||
|
///
|
||||||
|
/// Prefer [PRAGMA function](https://sqlite.org/pragma.html#pragfunc) introduced in SQLite 3.20:
|
||||||
|
/// `SELECT user_version FROM pragma_user_version;`
|
||||||
pub fn pragma_query_value<T, F>(
|
pub fn pragma_query_value<T, F>(
|
||||||
&self,
|
&self,
|
||||||
schema_name: Option<DatabaseName<'_>>,
|
schema_name: Option<DatabaseName<'_>>,
|
||||||
@ -183,6 +186,9 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Query the current rows/values of `pragma_name`.
|
/// Query the current rows/values of `pragma_name`.
|
||||||
|
///
|
||||||
|
/// Prefer [PRAGMA function](https://sqlite.org/pragma.html#pragfunc) introduced in SQLite 3.20:
|
||||||
|
/// `SELECT * FROM pragma_collation_list;`
|
||||||
pub fn pragma_query<F>(
|
pub fn pragma_query<F>(
|
||||||
&self,
|
&self,
|
||||||
schema_name: Option<DatabaseName<'_>>,
|
schema_name: Option<DatabaseName<'_>>,
|
||||||
@ -207,8 +213,11 @@ impl Connection {
|
|||||||
/// `pragma_value`.
|
/// `pragma_value`.
|
||||||
///
|
///
|
||||||
/// This method can be used with query-only pragmas which need an argument
|
/// This method can be used with query-only pragmas which need an argument
|
||||||
/// (e.g. `table_info('one_tbl')`) or pragmas which return the updated value
|
/// (e.g. `table_info('one_tbl')`) or pragmas which returns value(s)
|
||||||
/// (e.g. `journal_mode`).
|
/// (e.g. `integrity_check`).
|
||||||
|
///
|
||||||
|
/// Prefer [PRAGMA function](https://sqlite.org/pragma.html#pragfunc) introduced in SQLite 3.20:
|
||||||
|
/// `SELECT * FROM pragma_table_info(?);`
|
||||||
pub fn pragma<F>(
|
pub fn pragma<F>(
|
||||||
&self,
|
&self,
|
||||||
schema_name: Option<DatabaseName<'_>>,
|
schema_name: Option<DatabaseName<'_>>,
|
||||||
@ -318,7 +327,7 @@ fn is_identifier_continue(c: char) -> bool {
|
|||||||
mod test {
|
mod test {
|
||||||
use super::Sql;
|
use super::Sql;
|
||||||
use crate::pragma;
|
use crate::pragma;
|
||||||
use crate::{Connection, DatabaseName};
|
use crate::{Connection, DatabaseName, NO_PARAMS};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pragma_query_value() {
|
fn pragma_query_value() {
|
||||||
@ -329,6 +338,20 @@ mod test {
|
|||||||
assert_eq!(0, user_version);
|
assert_eq!(0, user_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(feature = "bundled")]
|
||||||
|
fn pragma_func_query_value() {
|
||||||
|
let db = Connection::open_in_memory().unwrap();
|
||||||
|
let user_version: i32 = db
|
||||||
|
.query_row(
|
||||||
|
"SELECT user_version FROM pragma_user_version",
|
||||||
|
NO_PARAMS,
|
||||||
|
|row| row.get(0),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(0, user_version);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pragma_query_no_schema() {
|
fn pragma_query_no_schema() {
|
||||||
let db = Connection::open_in_memory().unwrap();
|
let db = Connection::open_in_memory().unwrap();
|
||||||
@ -366,6 +389,22 @@ mod test {
|
|||||||
assert_eq!(5, columns.len());
|
assert_eq!(5, columns.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(feature = "bundled")]
|
||||||
|
fn pragma_func() {
|
||||||
|
let db = Connection::open_in_memory().unwrap();
|
||||||
|
let mut table_info = db.prepare("SELECT * FROM pragma_table_info(?)").unwrap();
|
||||||
|
let mut columns = Vec::new();
|
||||||
|
let mut rows = table_info.query(&["sqlite_master"]).unwrap();
|
||||||
|
|
||||||
|
while let Some(row) = rows.next() {
|
||||||
|
let row = row.unwrap();
|
||||||
|
let column: String = row.get(1);
|
||||||
|
columns.push(column);
|
||||||
|
}
|
||||||
|
assert_eq!(5, columns.len());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pragma_update() {
|
fn pragma_update() {
|
||||||
let db = Connection::open_in_memory().unwrap();
|
let db = Connection::open_in_memory().unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user