71 ByteString conns(_conns, _connslen);
72 ListedByteStringToByteStringMap map;
73 Connection::splitConnStr(_conns, _connslen, map);
75 ByteString _DATABASE = map[
"DATABASE"];
76 ByteString _URI = map[
"URI"];
77#ifdef SQLITE_HAS_CODEC
78 ByteString _KEY = map[
"KEY"];
79 ByteString _REKEY = map[
"REKEY"];
81 const char* pKey =
NULL;
83 if (_KEY.length() > 0) {
88 bool hasReKey = conns.searches(
"REKEY",
true);
89 const char* pReKey =
NULL;
91 if (_REKEY.length() > 0) {
92 pReKey = _REKEY.data();
93 nReKey = _REKEY.length();
97 int flags = SQLITE_OPEN_MEMORY;
98 const char* zVfs =
NULL;
99 if (!(_DATABASE.isEmpty())) {
101 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
103 else if (!(_URI.isEmpty())) {
104 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
106 else if (!conns.isEmpty()) {
108 if (!_URI.isEmpty()) {
109 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
113 flags = SQLITE_OPEN_MEMORY;
114 _URI.assign(
":memory:");
117 if (_URI.toLowerCase().startsWith(
"file:")) {
118 flags |= SQLITE_OPEN_URI;
127 sqlite3* conn =
NULL;
128 int rc = sqlite3_open_v2(_URI, &conn, flags, zVfs);
129 if (rc != SQLITE_OK) {
135#ifdef SQLITE_HAS_CODEC
136 rc = sqlite3_key(conn, pKey, nKey);
137 if (rc != SQLITE_OK) {
142 (pKey ? pKey :
"(nil)"), nKey);
144 rc = sqlite3_rekey(conn, pReKey, nReKey);
145 if (rc != SQLITE_OK) {
156 sqlite3_close_v2(conn);