74{
75 ByteString conns(_conns, _connslen);
76 ListedByteStringToByteStringMap map;
77 Connection::splitConnStr(_conns, _connslen, map);
78
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"];
84
85 const char* pKey =
NULL;
86 int nKey = 0;
87 if (_KEY.length() > 0) {
88 pKey = _KEY.data();
89 nKey = _KEY.length();
90 }
91
92 bool hasReKey = conns.searches("REKEY", true);
93 const char* pReKey =
NULL;
94 int nReKey = 0;
95 if (_REKEY.length() > 0) {
96 pReKey = _REKEY.data();
97 nReKey = _REKEY.length();
98 }
99#endif
100
101 int flags = SQLITE_OPEN_MEMORY;
102 const char* zVfs =
NULL;
103 if (!(_DATABASE.isEmpty())) {
104 _URI = _DATABASE;
105 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
106 }
107 else if (!(_URI.isEmpty())) {
108 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
109 }
110 else if (!conns.isEmpty()) {
111 _URI = conns;
112 if (!_URI.isEmpty()) {
113 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
114 }
115 }
116 else {
117 flags = SQLITE_OPEN_MEMORY;
118 _URI.assign(":memory:");
119 }
120
121 if (_URI.toLowerCase().startsWith("file:")) {
122 flags |= SQLITE_OPEN_URI;
123 }
124
125#ifdef __WINNT__
126 zVfs = "win32-none";
127#else
128 zVfs = "unix-none";
129#endif
130
131 sqlite3* conn =
NULL;
132 int rc = sqlite3_open_v2(_URI, &conn, flags, zVfs);
133 if (rc != SQLITE_OK) {
135 return false;
136 }
137
138 for ( ; ; ) {
139#ifdef SQLITE_HAS_CODEC
140 rc = sqlite3_key(conn, pKey, nKey);
141 if (rc != SQLITE_OK) {
143 break;
144 }
146 (pKey ? pKey : "(nil)"), nKey);
147 if (hasReKey) {
148 rc = sqlite3_rekey(conn, pReKey, nReKey);
149 if (rc != SQLITE_OK) {
151 break;
152 }
153 }
154#endif
155 __conn = conn;
156 return true;
157 }
158
159 if (conn) {
160 sqlite3_close_v2(conn);
161 }
162 return false;
163}
#define __DCL_TRACE2_N(fmt, arg1, arg2)