public bool Open(String path) { if (IsOpen) { return(true); } Path = path; var errMessage = "Cannot open Sqlite Database at pth {0}".Fmt(path); var result = true; try { shouldCommit = false; const int flags = SQLITE_OPEN_FILEPROTECTION_COMPLETEUNLESSOPEN | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX; var status = raw.sqlite3_open_v2(Path, out db, flags, null); if (status != raw.SQLITE_OK) { throw new CouchbaseLiteException(errMessage, StatusCode.DbError); } #if !__ANDROID__ && VERBOSE var i = 0; var val = raw.sqlite3_compileoption_get(i); while (val != null) { Log.V(Tag, "Sqlite Config: {0}".Fmt(val)); val = raw.sqlite3_compileoption_get(++i); } #endif db.create_collation("JSON", null, CouchbaseSqliteJsonUnicodeCollationFunction.Compare); db.create_collation("JSON_ASCII", null, CouchbaseSqliteJsonAsciiCollationFunction.Compare); db.create_collation("JSON_RAW", null, CouchbaseSqliteJsonRawCollationFunction.Compare); db.create_collation("REVID", null, CouchbaseSqliteRevIdCollationFunction.Compare); } catch (Exception ex) { Log.E(Tag, "Error opening the Sqlite connection using connection String: {0}".Fmt(path), ex); result = false; } return(result); }
public void test_collation() { using (sqlite3 db = ugly.open(":memory:")) { db.create_collation("e2a", null, my_collation); db.exec("CREATE TABLE foo (x text COLLATE e2a);"); db.exec("INSERT INTO foo (x) VALUES ('b')"); db.exec("INSERT INTO foo (x) VALUES ('c')"); db.exec("INSERT INTO foo (x) VALUES ('d')"); db.exec("INSERT INTO foo (x) VALUES ('e')"); db.exec("INSERT INTO foo (x) VALUES ('f')"); string top = db.query_scalar <string>("SELECT x FROM foo ORDER BY x ASC LIMIT 1;"); Assert.AreEqual(top, "e"); } }