mirror of
https://github.com/isar/rusqlite.git
synced 2025-10-07 12:02:19 +08:00
Merge remote-tracking branch 'jgallagher/master' into vtab
This commit is contained in:
@@ -1,19 +1,26 @@
|
||||
[package]
|
||||
name = "libsqlite3-sys"
|
||||
version = "0.6.0"
|
||||
version = "0.7.1"
|
||||
authors = ["John Gallagher <jgallagher@bignerdranch.com>"]
|
||||
repository = "https://github.com/jgallagher/rusqlite"
|
||||
description = "Native bindings to the libsqlite3 library"
|
||||
license = "MIT"
|
||||
links = "sqlite3"
|
||||
build = "build.rs"
|
||||
keywords = ["sqlite", "database", "ffi"]
|
||||
categories = ["database", "external-ffi-bindings"]
|
||||
|
||||
[features]
|
||||
bundled = []
|
||||
default = ["min_sqlite_version_3_6_8"]
|
||||
bundled = ["gcc"]
|
||||
buildtime_bindgen = ["bindgen", "pkg-config"]
|
||||
min_sqlite_version_3_6_8 = ["pkg-config"]
|
||||
min_sqlite_version_3_6_11 = ["pkg-config"]
|
||||
min_sqlite_version_3_6_23 = ["pkg-config"]
|
||||
min_sqlite_version_3_7_3 = ["pkg-config"]
|
||||
min_sqlite_version_3_7_4 = ["pkg-config"]
|
||||
|
||||
[build-dependencies]
|
||||
pkg-config = "~0.3"
|
||||
gcc = "~0.3"
|
||||
|
||||
[dependencies]
|
||||
libc = "~0.2"
|
||||
bindgen = { version = "0.21", optional = true }
|
||||
pkg-config = { version = "0.3", optional = true }
|
||||
gcc = { version = "0.3", optional = true }
|
||||
|
1863
libsqlite3-sys/bindgen-bindings/bindgen_3.6.11.rs
Normal file
1863
libsqlite3-sys/bindgen-bindings/bindgen_3.6.11.rs
Normal file
File diff suppressed because it is too large
Load Diff
1900
libsqlite3-sys/bindgen-bindings/bindgen_3.6.23.rs
Normal file
1900
libsqlite3-sys/bindgen-bindings/bindgen_3.6.23.rs
Normal file
File diff suppressed because it is too large
Load Diff
1835
libsqlite3-sys/bindgen-bindings/bindgen_3.6.8.rs
Normal file
1835
libsqlite3-sys/bindgen-bindings/bindgen_3.6.8.rs
Normal file
File diff suppressed because it is too large
Load Diff
2050
libsqlite3-sys/bindgen-bindings/bindgen_3.7.3.rs
Normal file
2050
libsqlite3-sys/bindgen-bindings/bindgen_3.7.3.rs
Normal file
File diff suppressed because it is too large
Load Diff
2059
libsqlite3-sys/bindgen-bindings/bindgen_3.7.4.rs
Normal file
2059
libsqlite3-sys/bindgen-bindings/bindgen_3.7.4.rs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,53 +1,193 @@
|
||||
extern crate gcc;
|
||||
extern crate pkg_config;
|
||||
|
||||
#[cfg(not(feature = "bundled"))]
|
||||
fn main() {
|
||||
use std::env;
|
||||
use std::fs;
|
||||
|
||||
// Allow users to specify where to find SQLite.
|
||||
let lib_dir = match env::var("SQLITE3_LIB_DIR") {
|
||||
Ok(dir) => dir,
|
||||
Err(_) => {
|
||||
// See if pkg-config can do everything for us.
|
||||
if pkg_config::find_library("sqlite3").is_ok() {
|
||||
return
|
||||
}
|
||||
|
||||
// Try to fall back to /usr/lib if pkg-config failed.
|
||||
match fs::metadata("/usr/lib") {
|
||||
Ok(ref attr) if attr.is_dir() => "/usr/lib".to_owned(),
|
||||
_ => panic!("Could not find sqlite3. Try setting SQLITE3_LIB_DIR."),
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
println!("cargo:rustc-link-lib=sqlite3");
|
||||
println!("cargo:rustc-link-search={}", lib_dir);
|
||||
build::main();
|
||||
}
|
||||
|
||||
#[cfg(feature = "bundled")]
|
||||
fn main() {
|
||||
gcc::Config::new()
|
||||
.file("sqlite3/sqlite3.c")
|
||||
.flag("-DSQLITE_CORE")
|
||||
.flag("-DSQLITE_DEFAULT_FOREIGN_KEYS=1")
|
||||
.flag("-DSQLITE_ENABLE_API_ARMOR")
|
||||
.flag("-DSQLITE_ENABLE_COLUMN_METADATA")
|
||||
.flag("-DSQLITE_ENABLE_DBSTAT_VTAB")
|
||||
.flag("-DSQLITE_ENABLE_FTS3")
|
||||
.flag("-DSQLITE_ENABLE_FTS3_PARENTHESIS")
|
||||
.flag("-DSQLITE_ENABLE_FTS5")
|
||||
.flag("-DSQLITE_ENABLE_JSON1")
|
||||
.flag("-DSQLITE_ENABLE_LOAD_EXTENSION=1")
|
||||
.flag("-DSQLITE_ENABLE_MEMORY_MANAGEMENT")
|
||||
.flag("-DSQLITE_ENABLE_RTREE")
|
||||
.flag("-DSQLITE_ENABLE_STAT2")
|
||||
.flag("-DSQLITE_ENABLE_STAT4")
|
||||
.flag("-DSQLITE_HAVE_ISNAN")
|
||||
.flag("-DSQLITE_SOUNDEX")
|
||||
.flag("-DSQLITE_THREADSAFE=1")
|
||||
.flag("-DSQLITE_USE_URI")
|
||||
.compile("libsqlite3.a");
|
||||
mod build {
|
||||
extern crate gcc;
|
||||
use std::{env, fs};
|
||||
use std::path::Path;
|
||||
|
||||
pub fn main() {
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
let out_path = Path::new(&out_dir).join("bindgen.rs");
|
||||
fs::copy("sqlite3/bindgen_bundled_version.rs", out_path)
|
||||
.expect("Could not copy bindings to output directory");
|
||||
|
||||
gcc::Config::new()
|
||||
.file("sqlite3/sqlite3.c")
|
||||
.flag("-DSQLITE_CORE")
|
||||
.flag("-DSQLITE_DEFAULT_FOREIGN_KEYS=1")
|
||||
.flag("-DSQLITE_ENABLE_API_ARMOR")
|
||||
.flag("-DSQLITE_ENABLE_COLUMN_METADATA")
|
||||
.flag("-DSQLITE_ENABLE_DBSTAT_VTAB")
|
||||
.flag("-DSQLITE_ENABLE_FTS3")
|
||||
.flag("-DSQLITE_ENABLE_FTS3_PARENTHESIS")
|
||||
.flag("-DSQLITE_ENABLE_FTS5")
|
||||
.flag("-DSQLITE_ENABLE_JSON1")
|
||||
.flag("-DSQLITE_ENABLE_LOAD_EXTENSION=1")
|
||||
.flag("-DSQLITE_ENABLE_MEMORY_MANAGEMENT")
|
||||
.flag("-DSQLITE_ENABLE_RTREE")
|
||||
.flag("-DSQLITE_ENABLE_STAT2")
|
||||
.flag("-DSQLITE_ENABLE_STAT4")
|
||||
.flag("-DSQLITE_HAVE_ISNAN")
|
||||
.flag("-DSQLITE_SOUNDEX")
|
||||
.flag("-DSQLITE_THREADSAFE=1")
|
||||
.flag("-DSQLITE_USE_URI")
|
||||
.compile("libsqlite3.a");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "bundled"))]
|
||||
mod build {
|
||||
extern crate pkg_config;
|
||||
|
||||
use std::env;
|
||||
|
||||
pub enum HeaderLocation {
|
||||
FromEnvironment,
|
||||
Wrapper,
|
||||
FromPath(String),
|
||||
}
|
||||
|
||||
impl From<HeaderLocation> for String {
|
||||
fn from(header: HeaderLocation) -> String {
|
||||
match header {
|
||||
HeaderLocation::FromEnvironment => {
|
||||
let mut header = env::var("SQLITE3_INCLUDE_DIR")
|
||||
.expect("SQLITE3_INCLUDE_DIR must be set if SQLITE3_LIB_DIR is set");
|
||||
header.push_str("/sqlite3.h");
|
||||
header
|
||||
}
|
||||
HeaderLocation::Wrapper => "wrapper.h".into(),
|
||||
HeaderLocation::FromPath(path) => path,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let header = find_sqlite();
|
||||
bindings::write_to_out_dir(header);
|
||||
}
|
||||
|
||||
// Prints the necessary cargo link commands and returns the path to the header.
|
||||
fn find_sqlite() -> HeaderLocation {
|
||||
// Allow users to specify where to find SQLite.
|
||||
if let Ok(dir) = env::var("SQLITE3_LIB_DIR") {
|
||||
println!("cargo:rustc-link-lib=sqlite3");
|
||||
println!("cargo:rustc-link-search={}", dir);
|
||||
return HeaderLocation::FromEnvironment;
|
||||
}
|
||||
|
||||
// See if pkg-config can do everything for us.
|
||||
match pkg_config::Config::new().print_system_libs(false).probe("sqlite3") {
|
||||
Ok(mut lib) => {
|
||||
if let Some(mut header) = lib.include_paths.pop() {
|
||||
header.push("sqlite3.h");
|
||||
HeaderLocation::FromPath(header.to_string_lossy().into())
|
||||
} else {
|
||||
HeaderLocation::Wrapper
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
// No env var set and pkg-config couldn't help; just output the link-lib
|
||||
// request and hope that the library exists on the system paths. We used to
|
||||
// output /usr/lib explicitly, but that can introduce other linking problems; see
|
||||
// https://github.com/jgallagher/rusqlite/issues/207.
|
||||
println!("cargo:rustc-link-lib=sqlite3");
|
||||
HeaderLocation::Wrapper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "buildtime_bindgen"))]
|
||||
mod bindings {
|
||||
use super::HeaderLocation;
|
||||
|
||||
use std::{env, fs};
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
static PREBUILT_BINDGEN_PATHS: &'static [&'static str] = &[
|
||||
"bindgen-bindings/bindgen_3.6.8.rs",
|
||||
|
||||
#[cfg(feature = "min_sqlite_version_3_6_11")]
|
||||
"bindgen-bindings/bindgen_3.6.11.rs",
|
||||
|
||||
#[cfg(feature = "min_sqlite_version_3_6_23")]
|
||||
"bindgen-bindings/bindgen_3.6.23.rs",
|
||||
|
||||
#[cfg(feature = "min_sqlite_version_3_7_3")]
|
||||
"bindgen-bindings/bindgen_3.7.3.rs",
|
||||
|
||||
#[cfg(feature = "min_sqlite_version_3_7_4")]
|
||||
"bindgen-bindings/bindgen_3.7.4.rs",
|
||||
];
|
||||
|
||||
pub fn write_to_out_dir(_header: HeaderLocation) {
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
let out_path = Path::new(&out_dir).join("bindgen.rs");
|
||||
let in_path = PREBUILT_BINDGEN_PATHS[PREBUILT_BINDGEN_PATHS.len() - 1];
|
||||
fs::copy(in_path, out_path).expect("Could not copy bindings to output directory");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "buildtime_bindgen")]
|
||||
mod bindings {
|
||||
extern crate bindgen;
|
||||
|
||||
use self::bindgen::chooser::{TypeChooser, IntKind};
|
||||
use super::HeaderLocation;
|
||||
|
||||
use std::env;
|
||||
use std::io::Write;
|
||||
use std::fs::OpenOptions;
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct SqliteTypeChooser;
|
||||
|
||||
impl TypeChooser for SqliteTypeChooser {
|
||||
fn int_macro(&self, _name: &str, value: i64) -> Option<IntKind> {
|
||||
if value >= i32::min_value() as i64 && value <= i32::max_value() as i64 {
|
||||
Some(IntKind::I32)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_to_out_dir(header: HeaderLocation) {
|
||||
let header: String = header.into();
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
let mut output = Vec::new();
|
||||
bindgen::builder()
|
||||
.header(header.clone())
|
||||
.type_chooser(Box::new(SqliteTypeChooser))
|
||||
.generate()
|
||||
.expect(&format!("could not run bindgen on header {}", header))
|
||||
.write(Box::new(&mut output))
|
||||
.expect("could not write output of bindgen");
|
||||
let mut output = String::from_utf8(output).expect("bindgen output was not UTF-8?!");
|
||||
|
||||
// rusqlite's functions feature ors in the SQLITE_DETERMINISTIC flag when it can. This flag
|
||||
// was added in SQLite 3.8.3, but oring it in in prior versions of SQLite is harmless. We
|
||||
// don't want to not build just because this flag is missing (e.g., if we're linking against
|
||||
// SQLite 3.7.x), so append the flag manually if it isn't present in bindgen's output.
|
||||
if !output.contains("pub const SQLITE_DETERMINISTIC:") {
|
||||
output.push_str("\npub const SQLITE_DETERMINISTIC: i32 = 2048;\n");
|
||||
}
|
||||
|
||||
let path = Path::new(&out_dir).join("bindgen.rs");
|
||||
|
||||
let mut file = OpenOptions::new()
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.create(true)
|
||||
.open(path.clone())
|
||||
.expect(&format!("Could not write to {:?}", path));
|
||||
|
||||
file.write_all(output.as_bytes()).expect(&format!("Could not write to {:?}", path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -15,12 +15,10 @@
|
||||
** as extensions by SQLite should #include this file instead of
|
||||
** sqlite3.h.
|
||||
*/
|
||||
#ifndef _SQLITE3EXT_H_
|
||||
#define _SQLITE3EXT_H_
|
||||
#ifndef SQLITE3EXT_H
|
||||
#define SQLITE3EXT_H
|
||||
#include "sqlite3.h"
|
||||
|
||||
typedef struct sqlite3_api_routines sqlite3_api_routines;
|
||||
|
||||
/*
|
||||
** The following structure holds pointers to all of the SQLite API
|
||||
** routines.
|
||||
@@ -281,8 +279,21 @@ struct sqlite3_api_routines {
|
||||
int (*db_cacheflush)(sqlite3*);
|
||||
/* Version 3.12.0 and later */
|
||||
int (*system_errno)(sqlite3*);
|
||||
/* Version 3.14.0 and later */
|
||||
int (*trace_v2)(sqlite3*,unsigned,int(*)(unsigned,void*,void*,void*),void*);
|
||||
char *(*expanded_sql)(sqlite3_stmt*);
|
||||
};
|
||||
|
||||
/*
|
||||
** This is the function signature used for all extension entry points. It
|
||||
** is also defined in the file "loadext.c".
|
||||
*/
|
||||
typedef int (*sqlite3_loadext_entry)(
|
||||
sqlite3 *db, /* Handle to the database. */
|
||||
char **pzErrMsg, /* Used to set error string on failure. */
|
||||
const sqlite3_api_routines *pThunk /* Extension API function pointers. */
|
||||
);
|
||||
|
||||
/*
|
||||
** The following macros redefine the API routines so that they are
|
||||
** redirected through the global sqlite3_api structure.
|
||||
@@ -526,6 +537,9 @@ struct sqlite3_api_routines {
|
||||
#define sqlite3_db_cacheflush sqlite3_api->db_cacheflush
|
||||
/* Version 3.12.0 and later */
|
||||
#define sqlite3_system_errno sqlite3_api->system_errno
|
||||
/* Version 3.14.0 and later */
|
||||
#define sqlite3_trace_v2 sqlite3_api->trace_v2
|
||||
#define sqlite3_expanded_sql sqlite3_api->expanded_sql
|
||||
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
|
||||
|
||||
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
|
||||
@@ -543,4 +557,4 @@ struct sqlite3_api_routines {
|
||||
# define SQLITE_EXTENSION_INIT3 /*no-op*/
|
||||
#endif
|
||||
|
||||
#endif /* _SQLITE3EXT_H_ */
|
||||
#endif /* SQLITE3EXT_H */
|
||||
|
@@ -1,32 +1,57 @@
|
||||
use libc::c_int;
|
||||
use std::os::raw::c_int;
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
|
||||
/// Error Codes
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum ErrorCode {
|
||||
/// Internal logic error in SQLite
|
||||
InternalMalfunction,
|
||||
/// Access permission denied
|
||||
PermissionDenied,
|
||||
/// Callback routine requested an abort
|
||||
OperationAborted,
|
||||
/// The database file is locked
|
||||
DatabaseBusy,
|
||||
/// A table in the database is locked
|
||||
DatabaseLocked,
|
||||
/// A malloc() failed
|
||||
OutOfMemory,
|
||||
/// Attempt to write a readonly database
|
||||
ReadOnly,
|
||||
/// Operation terminated by sqlite3_interrupt()
|
||||
OperationInterrupted,
|
||||
/// Some kind of disk I/O error occurred
|
||||
SystemIOFailure,
|
||||
/// The database disk image is malformed
|
||||
DatabaseCorrupt,
|
||||
/// Unknown opcode in sqlite3_file_control()
|
||||
NotFound,
|
||||
/// Insertion failed because database is full
|
||||
DiskFull,
|
||||
/// Unable to open the database file
|
||||
CannotOpen,
|
||||
/// Database lock protocol error
|
||||
FileLockingProtocolFailed,
|
||||
/// The database schema changed
|
||||
SchemaChanged,
|
||||
/// String or BLOB exceeds size limit
|
||||
TooBig,
|
||||
/// Abort due to constraint violation
|
||||
ConstraintViolation,
|
||||
/// Data type mismatch
|
||||
TypeMismatch,
|
||||
/// Library used incorrectly
|
||||
APIMisuse,
|
||||
/// Uses OS features not supported on host
|
||||
NoLargeFileSupport,
|
||||
/// Authorization denied
|
||||
AuthorizationForStatementDenied,
|
||||
/// 2nd parameter to sqlite3_bind out of range
|
||||
ParameterOutOfRange,
|
||||
/// File opened that is not a database file
|
||||
NotADatabase,
|
||||
/// SQL error or missing database
|
||||
Unknown,
|
||||
}
|
||||
|
||||
|
@@ -1,25 +1,12 @@
|
||||
// bindgen.rs was created with bindgen 0.15.0 against sqlite3 3.8.10
|
||||
#![allow(non_snake_case, non_camel_case_types)]
|
||||
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
pub use self::bindgen::*;
|
||||
pub use self::error::*;
|
||||
|
||||
use std::default::Default;
|
||||
use std::mem;
|
||||
use libc::c_int;
|
||||
|
||||
mod bindgen;
|
||||
mod error;
|
||||
|
||||
// SQLite datatype constants.
|
||||
pub const SQLITE_INTEGER : c_int = 1;
|
||||
pub const SQLITE_FLOAT : c_int = 2;
|
||||
pub const SQLITE_TEXT : c_int = 3;
|
||||
pub const SQLITE_BLOB : c_int = 4;
|
||||
pub const SQLITE_NULL : c_int = 5;
|
||||
|
||||
pub fn SQLITE_STATIC() -> sqlite3_destructor_type {
|
||||
Some(unsafe { mem::transmute(0isize) })
|
||||
}
|
||||
@@ -28,6 +15,45 @@ pub fn SQLITE_TRANSIENT() -> sqlite3_destructor_type {
|
||||
Some(unsafe { mem::transmute(-1isize) })
|
||||
}
|
||||
|
||||
pub const SQLITE_CONFIG_LOG : c_int = 16;
|
||||
pub const SQLITE_UTF8 : c_int = 1;
|
||||
pub const SQLITE_DETERMINISTIC : c_int = 0x800;
|
||||
/// Run-Time Limit Categories
|
||||
#[repr(C)]
|
||||
pub enum Limit {
|
||||
/// The maximum size of any string or BLOB or table row, in bytes.
|
||||
SQLITE_LIMIT_LENGTH = 0,
|
||||
/// The maximum length of an SQL statement, in bytes.
|
||||
SQLITE_LIMIT_SQL_LENGTH = 1,
|
||||
/// The maximum number of columns in a table definition or in the result set of a SELECT
|
||||
/// or the maximum number of columns in an index or in an ORDER BY or GROUP BY clause.
|
||||
SQLITE_LIMIT_COLUMN = 2,
|
||||
/// The maximum depth of the parse tree on any expression.
|
||||
SQLITE_LIMIT_EXPR_DEPTH = 3,
|
||||
/// The maximum number of terms in a compound SELECT statement.
|
||||
SQLITE_LIMIT_COMPOUND_SELECT = 4,
|
||||
/// The maximum number of instructions in a virtual machine program used to implement an SQL statement.
|
||||
SQLITE_LIMIT_VDBE_OP = 5,
|
||||
/// The maximum number of arguments on a function.
|
||||
SQLITE_LIMIT_FUNCTION_ARG = 6,
|
||||
/// The maximum number of attached databases.
|
||||
SQLITE_LIMIT_ATTACHED = 7,
|
||||
/// The maximum length of the pattern argument to the LIKE or GLOB operators.
|
||||
SQLITE_LIMIT_LIKE_PATTERN_LENGTH = 8,
|
||||
/// The maximum index number of any parameter in an SQL statement.
|
||||
SQLITE_LIMIT_VARIABLE_NUMBER = 9,
|
||||
/// The maximum depth of recursion for triggers.
|
||||
SQLITE_LIMIT_TRIGGER_DEPTH = 10,
|
||||
/// The maximum number of auxiliary worker threads that a single prepared statement may start.
|
||||
SQLITE_LIMIT_WORKER_THREADS = 11,
|
||||
}
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bindgen.rs"));
|
||||
|
||||
pub type sqlite3_index_constraint = sqlite3_index_info_sqlite3_index_constraint;
|
||||
pub type sqlite3_index_constraint_usage = sqlite3_index_info_sqlite3_index_constraint_usage;
|
||||
|
||||
impl Default for sqlite3_vtab {
|
||||
fn default() -> Self { unsafe { mem::zeroed() } }
|
||||
}
|
||||
|
||||
impl Default for sqlite3_vtab_cursor {
|
||||
fn default() -> Self { unsafe { mem::zeroed() } }
|
||||
}
|
1
libsqlite3-sys/wrapper.h
Normal file
1
libsqlite3-sys/wrapper.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "sqlite3.h"
|
Reference in New Issue
Block a user