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