75 ByteString conns(_conns, _connslen);
76 ListedByteStringToByteStringMap map;
77 Connection::splitConnStr(_conns, _connslen, map);
79 ByteString _DATABASE = map[
"DATABASE"];
80 ByteString _URI = map[
"URI"];
81#ifdef SQLITE_HAS_CODEC
82 ByteString _KEY = map[
"KEY"];
83 ByteString _REKEY = map[
"REKEY"];
85 const char* pKey =
NULL;
87 if (_KEY.length() > 0) {
92 bool hasReKey = conns.searches(
"REKEY",
true);
93 const char* pReKey =
NULL;
95 if (_REKEY.length() > 0) {
96 pReKey = _REKEY.data();
97 nReKey = _REKEY.length();
101 int flags = SQLITE_OPEN_MEMORY;
102 const char* zVfs =
NULL;
103 if (!(_DATABASE.isEmpty())) {
105 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
107 else if (!(_URI.isEmpty())) {
108 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
110 else if (!conns.isEmpty()) {
112 if (!_URI.isEmpty()) {
113 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
117 flags = SQLITE_OPEN_MEMORY;
118 _URI.assign(
":memory:");
121 if (_URI.toLowerCase().startsWith(
"file:")) {
122 flags |= SQLITE_OPEN_URI;
131 sqlite3* conn =
NULL;
132 int rc = sqlite3_open_v2(_URI, &conn, flags, zVfs);
133 if (rc != SQLITE_OK) {
139#ifdef SQLITE_HAS_CODEC
140 rc = sqlite3_key(conn, pKey, nKey);
141 if (rc != SQLITE_OK) {
146 (pKey ? pKey :
"(nil)"), nKey);
148 rc = sqlite3_rekey(conn, pReKey, nReKey);
149 if (rc != SQLITE_OK) {
160 sqlite3_close_v2(conn);