Skip to content

Commit

Permalink
fixed "Cannot open table" issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaobin80 committed Jun 13, 2020
1 parent 0865331 commit 96b7092
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions SerialCommDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,22 @@ CSerialCommDoc::workerLogRecord(CStringA strA, int flag, int lineNum) {
return boost::thread();
}

int checkTable(sqlite3 *db, char *tableName) {
int rc;
int checkTable(char *dbName, char *tableName) {
sqlite3 *db;
char *zErrMsg = 0;
int rc;
const char* data = "Callback function called";

char *sql;
int len, len1 = 0;

rc = sqlite3_open(dbName, &db);

if (rc) {
fprintf_s(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
return(-3);
}

/// Create SQL statement
char *sql1 = "SELECT * from ";
len1 = strlen(sql1);
Expand All @@ -329,9 +337,11 @@ int checkTable(sqlite3 *db, char *tableName) {
if (rc != SQLITE_OK) {
fprintf_s(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
return(-1);
return(-4);
}

sqlite3_close(db);

return 0;
}

Expand All @@ -348,21 +358,20 @@ int CSerialCommDoc::checkDB(char *dbName, char *tableName) {
fprintf_s(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
return(-1);
}
else {
if (checkTable(db, tableName) != 0)
return(-2);
else {
/// Assignment to member variables
len_db = strlen(dbName) + 1;
m_dbName = (char *)malloc(len_db);
strcpy_s(m_dbName, len_db, dbName);
len_table = strlen(tableName) + 1;
m_tableName = (char *)malloc(len_table);
strcpy_s(m_tableName, len_table, tableName);
}
}

sqlite3_close(db);

if (checkTable(dbName, tableName) != 0)
return(-2);
else {
/// Assignment to member variables
len_db = strlen(dbName) + 1;
m_dbName = (char *)malloc(len_db);
strcpy_s(m_dbName, len_db, dbName);
len_table = strlen(tableName) + 1;
m_tableName = (char *)malloc(len_table);
strcpy_s(m_tableName, len_table, tableName);
}

return 0;
}

0 comments on commit 96b7092

Please sign in to comment.