75 WORD errlen, errmax =
sizeof (errmsg) - 1;
81 rc = SQLInstallerError(err, &code, errmsg, errmax, &errlen);
82 if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) {
84 MessageBox(NULL, errmsg, name,
85 MB_ICONSTOP|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND);
90 }
while (rc != SQL_NO_DATA);
104 char firstpat[MAX_PATH];
105 WIN32_FIND_DATA fdata;
109 if (strncmp(dllname,
"sqlite3", 7)) {
114 strcpy(firstpat, path);
115 strcat(firstpat,
"\\");
117 strcat(firstpat,
"sqlite3_mod*.dll");
118 h = FindFirstFile(firstpat, &fdata);
119 if (h == INVALID_HANDLE_VALUE) {
124 DeleteFile(fdata.cFileName);
128 sprintf(buf,
"%s\\%s", path, fdata.cFileName);
129 if (!CopyFile(fdata.cFileName, buf, 0)) {
130 sprintf(buf,
"Copy %s to %s failed", fdata.cFileName, path);
131 MessageBox(NULL, buf,
"CopyFile",
132 MB_ICONSTOP|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND);
137 }
while (FindNextFile(h, &fdata));
138 err = GetLastError();
140 return err == ERROR_NO_MORE_FILES;
153InUn(
int remove,
char *drivername,
char *dllname,
char *dll2name,
char *dsname)
155 char path[301], driver[300], attr[300], inst[400], inst2[400];
156 WORD pathmax =
sizeof (path) - 1, pathlen;
157 DWORD usecnt, mincnt;
159 if (SQLInstallDriverManager(path, pathmax, &pathlen)) {
162 sprintf(driver,
"%s;Driver=%s;Setup=%s;",
163 drivername, dllname, dllname);
172 SQLInstallDriverEx(driver, NULL, path, pathmax, &pathlen,
173 ODBC_INSTALL_INQUIRY, &usecnt);
174 sprintf(driver,
"%s;Driver=%s\\%s;Setup=%s\\%s;",
175 drivername, path, dllname, path, dllname);
183 sprintf(inst,
"%s\\%s", path, dllname);
185 sprintf(inst2,
"%s\\%s", path, dll2name);
187 if (!remove && usecnt > 0) {
189 if (GetFileAttributes(dllname) != INVALID_FILE_ATTRIBUTES &&
190 CopyFile(dllname, inst, 0) &&
192 if (dll2name != NULL) {
193 CopyFile(dll2name, inst2, 0);
198 mincnt = remove ? 1 : 0;
199 while (usecnt != mincnt) {
200 if (!SQLRemoveDriver(driver, TRUE, &usecnt)) {
205 if (!SQLRemoveDriver(driver, TRUE, &usecnt)) {
206 if (GetFileAttributes(dllname) != INVALID_FILE_ATTRIBUTES) {
220 sprintf(buf,
"%s uninstalled.", drivername);
221 MessageBox(NULL, buf,
"Info",
222 MB_ICONINFORMATION|MB_OK|MB_TASKMODAL|
229 sprintf(attr,
"DSN=%s;Database=", dsname);
237 SQLConfigDataSource(NULL, ODBC_REMOVE_SYS_DSN, drivername, attr);
240 if (GetFileAttributes(dllname) == INVALID_FILE_ATTRIBUTES) {
243 if (!CopyFile(dllname, inst, 0)) {
246 sprintf(buf,
"Copy %s to %s failed", dllname, inst);
247 MessageBox(NULL, buf,
"CopyFile",
248 MB_ICONSTOP|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND);
251 if (dll2name != NULL && !CopyFile(dll2name, inst2, 0)) {
254 sprintf(buf,
"Copy %s to %s failed", dll2name, inst2);
255 MessageBox(NULL, buf,
"CopyFile",
256 MB_ICONSTOP|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND);
262 if (!SQLInstallDriverEx(driver, path, path, pathmax, &pathlen,
263 ODBC_INSTALL_COMPLETE, &usecnt)) {
270 sprintf(attr,
"DSN=%s;Database=;", dsname);
278 SQLConfigDataSource(NULL, ODBC_REMOVE_SYS_DSN, drivername, attr);
279 if (!SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, drivername, attr)) {
299WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
300 LPSTR lpszCmdLine,
int nCmdShow)
306 GetModuleFileName(NULL, path,
sizeof (path));
312 p = strrchr(path,
'\\');
318 SetCurrentDirectory(path);
320 remove = strstr(p,
"uninst") != NULL;
321 quiet = strstr(p,
"instq") != NULL;
322 nosys = strstr(p,
"nosys") != NULL;
323 for (i = 0; i <
NUMDRVS; i++) {
324#if defined(WITH_SQLITE_DLLS) && (WITH_SQLITE_DLLS <= 1)
331 for (i = 1; i <
NUMDRVS; i++) {
332 ret[0] = ret[0] || ret[i];
334 if (!remove && ret[0]) {
336 MessageBox(NULL,
"SQLite ODBC Driver(s) installed.",
"Info",
337 MB_ICONINFORMATION|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Main function of installer/uninstaller.
static BOOL InUn(int remove, char *drivername, char *dllname, char *dll2name, char *dsname)
Driver installer/uninstaller.