static void test_SQLInstallDriverManager(void) { BOOL bool_ret; RETCODE sql_ret; DWORD error_code; CHAR target_path[MAX_PATH]; WORD path_out; /* NULL check */ bool_ret = SQLInstallDriverManager(NULL, 0, NULL); sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n"); ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN, "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n"); /* Length smaller than MAX_PATH */ bool_ret = SQLInstallDriverManager(target_path, MAX_PATH / 2, NULL); sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n"); ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN, "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n"); path_out = 0xcafe; bool_ret = SQLInstallDriverManager(target_path, MAX_PATH / 2, &path_out); sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n"); ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN, "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n"); ok(path_out == 0xcafe, "Expected path_out to not have changed\n"); /* Length OK */ bool_ret = SQLInstallDriverManager(target_path, MAX_PATH, NULL); sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); if(!bool_ret && error_code == ODBC_ERROR_WRITING_SYSINFO_FAILED) { win_skip("not enough privileges\n"); return; } ok(bool_ret, "SQLInstallDriverManager unexpectedly failed: %d\n", error_code); if (bool_ret) ok(sql_ret == SQL_NO_DATA, "Expected SQL_NO_DATA, got %d\n", sql_ret); else ok(sql_ret == SQL_SUCCESS_WITH_INFO, "Expected SQL_SUCCESS_WITH_INFO, got %d\n", sql_ret); path_out = 0xcafe; bool_ret = SQLInstallDriverManager(target_path, MAX_PATH, &path_out); sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); ok(bool_ret, "SQLInstallDriverManager unexpectedly failed: %d\n", error_code); if (bool_ret) ok(sql_ret == SQL_NO_DATA, "Expected SQL_NO_DATA, got %d\n", sql_ret); else ok(sql_ret == SQL_SUCCESS_WITH_INFO, "Expected SQL_SUCCESS_WITH_INFO, got %d\n", sql_ret); /* path_out should in practice be less than 0xcafe */ ok(path_out != 0xcafe, "Expected path_out to show the correct amount of bytes\n"); }
BOOL INSTAPI SQLInstallDriverManagerW (LPWSTR lpszPath, WORD cbPathMax, WORD FAR * pcbPathOut) { char *_path_u8 = NULL; BOOL retcode = FALSE; if (cbPathMax > 0) { if ((_path_u8 = malloc (cbPathMax * UTF8_MAX_CHAR_LEN + 1)) == NULL) { PUSH_ERROR (ODBC_ERROR_OUT_OF_MEM); goto done; } } retcode = SQLInstallDriverManager (_path_u8, cbPathMax * UTF8_MAX_CHAR_LEN, pcbPathOut); if (retcode == TRUE) { dm_StrCopyOut2_U8toW (_path_u8, lpszPath, cbPathMax, pcbPathOut); } done: MEM_FREE (_path_u8); return retcode; }
static BOOL Install(const char *driverpath) { char path[300]; WORD pathlen; BOOL rc; DWORD usagecount; /* first, retrieve the path the driver should be installed to * in path */ if (!SQLInstallDriverManager(path, sizeof(path), &pathlen) && ProcessSQLErrorMessages("SQLInstallDriverManager")) return FALSE; if (!CheckIfFileExists(path, "odbc32.dll")) { MessageBox(NULL, "You must install MDAC before you can use the ODBC driver", "Install", MB_ICONSTOP | MB_OK | MB_TASKMODAL | MB_SETFOREGROUND); SQLRemoveDriverManager(&usagecount); return FALSE; } rc = InstallMyDriver(driverpath); if (rc) { /* after the driver is installed create the new DSN */ rc = AddMyDSN(); } if (!rc) SQLRemoveDriverManager(&usagecount); return rc; }
BOOL INSTAPI SQLInstallDriverManagerW (LPWSTR lpszPath, WORD cbPathMax, WORD * pcbPathOut) { char *path; BOOL ret; inst_logClear(); path = calloc( cbPathMax, 1 ); ret = SQLInstallDriverManager( path, cbPathMax, pcbPathOut ); if ( ret ) { _single_string_copy_to_wide( lpszPath, path, cbPathMax ); } free( path ); return ret; }
static BOOL InUn(int remove, char *drivername, char *dllname, char *dll2name, char *dsname) { char path[301], driver[300], attr[300], inst[400], inst2[400]; WORD pathmax = sizeof (path) - 1, pathlen; DWORD usecnt, mincnt; if (SQLInstallDriverManager(path, pathmax, &pathlen)) { char *p; sprintf(driver, "%s;Driver=%s;Setup=%s;", drivername, dllname, dllname); p = driver; while (*p) { if (*p == ';') { *p = '\0'; } ++p; } usecnt = 0; SQLInstallDriverEx(driver, NULL, path, pathmax, &pathlen, ODBC_INSTALL_INQUIRY, &usecnt); sprintf(driver, "%s;Driver=%s\\%s;Setup=%s\\%s;", drivername, path, dllname, path, dllname); p = driver; while (*p) { if (*p == ';') { *p = '\0'; } ++p; } sprintf(inst, "%s\\%s", path, dllname); if (dll2name) { sprintf(inst2, "%s\\%s", path, dll2name); } if (!remove && usecnt > 0) { /* first install try: copy over driver dll, keeping DSNs */ if (GetFileAttributes(dllname) != INVALID_FILE_ATTRIBUTES && CopyFile(dllname, inst, 0) && CopyOrDelModules(dllname, path, 0)) { if (dll2name != NULL) { CopyFile(dll2name, inst2, 0); } return TRUE; } } mincnt = remove ? 1 : 0; while (usecnt != mincnt) { if (!SQLRemoveDriver(driver, TRUE, &usecnt)) { break; } } if (remove) { if (!SQLRemoveDriver(driver, TRUE, &usecnt)) { ProcessErrorMessages("SQLRemoveDriver"); return FALSE; } if (!usecnt) { char buf[512]; DeleteFile(inst); /* but keep inst2 */ CopyOrDelModules(dllname, path, 1); if (!quiet) { sprintf(buf, "%s uninstalled.", drivername); MessageBox(NULL, buf, "Info", MB_ICONINFORMATION|MB_OK|MB_TASKMODAL| MB_SETFOREGROUND); } } if (nosys) { goto done; } sprintf(attr, "DSN=%s;Database=sqlite.db;", dsname); p = attr; while (*p) { if (*p == ';') { *p = '\0'; } ++p; } SQLConfigDataSource(NULL, ODBC_REMOVE_SYS_DSN, drivername, attr); goto done; } if (GetFileAttributes(dllname) == INVALID_FILE_ATTRIBUTES) { return FALSE; } if (!CopyFile(dllname, inst, 0)) { char buf[512]; sprintf(buf, "Copy %s to %s failed", dllname, inst); MessageBox(NULL, buf, "CopyFile", MB_ICONSTOP|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND); return FALSE; } if (dll2name != NULL && !CopyFile(dll2name, inst2, 0)) { char buf[512]; sprintf(buf, "Copy %s to %s failed", dll2name, inst2); MessageBox(NULL, buf, "CopyFile", MB_ICONSTOP|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND); /* but go on hoping that an SQLite engine is in place */ } if (!CopyOrDelModules(dllname, path, 0)) { return FALSE; } if (!SQLInstallDriverEx(driver, path, path, pathmax, &pathlen, ODBC_INSTALL_COMPLETE, &usecnt)) { ProcessErrorMessages("SQLInstallDriverEx"); return FALSE; } if (nosys) { goto done; } sprintf(attr, "DSN=%s;Database=sqlite.db;", dsname); p = attr; while (*p) { if (*p == ';') { *p = '\0'; } ++p; } SQLConfigDataSource(NULL, ODBC_REMOVE_SYS_DSN, drivername, attr); if (!SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, drivername, attr)) { ProcessErrorMessages("SQLConfigDataSource"); return FALSE; } } else { ProcessErrorMessages("SQLInstallDriverManager"); return FALSE; } done: return TRUE; }