diff options
author | Richard Knight <q@1bpm.net> | 2021-07-09 17:01:23 +0100 |
---|---|---|
committer | Richard Knight <q@1bpm.net> | 2021-07-09 17:01:23 +0100 |
commit | 6002b975544934cf8127040257ce630d8bc0d279 (patch) | |
tree | db1cd36a0bcc220cbd8836e23c01d80f5e70e450 /src | |
parent | 9c6d7766e9fceca9e988cfb057bee4b820840e33 (diff) | |
download | csound-sqldb-6002b975544934cf8127040257ce630d8bc0d279.tar.gz csound-sqldb-6002b975544934cf8127040257ce630d8bc0d279.tar.bz2 csound-sqldb-6002b975544934cf8127040257ce630d8bc0d279.zip |
fixed really idiotic locking order
Diffstat (limited to 'src')
-rw-r--r-- | src/mysql.cpp | 4 | ||||
-rw-r--r-- | src/opcodes.cpp | 82 | ||||
-rw-r--r-- | src/postgresql.cpp | 4 | ||||
-rw-r--r-- | src/sqlite3.cpp | 4 |
4 files changed, 50 insertions, 44 deletions
diff --git a/src/mysql.cpp b/src/mysql.cpp index 040670e..71ea16c 100644 --- a/src/mysql.cpp +++ b/src/mysql.cpp @@ -62,7 +62,7 @@ mysql::ResultSet* MySQLConnection::Query(char* sql) { return result; } -MYFLT MySQLConnection::Scalar(char* sql, int row=0, int col=0) { +MYFLT MySQLConnection::Scalar(char* sql, int row, int col) { mysql::ResultSet* res = Query(sql); mysql::ResultSetMetaData* meta = res->getMetaData(); int colCount = meta->getColumnCount(); @@ -78,7 +78,7 @@ MYFLT MySQLConnection::Scalar(char* sql, int row=0, int col=0) { return result; } -char* MySQLConnection::ScalarString(char* sql, int row=0, int col=0) { +char* MySQLConnection::ScalarString(char* sql, int row, int col) { mysql::ResultSet* res = Query(sql); mysql::ResultSetMetaData* meta = res->getMetaData(); diff --git a/src/opcodes.cpp b/src/opcodes.cpp index 94831f5..c64bb38 100644 --- a/src/opcodes.cpp +++ b/src/opcodes.cpp @@ -99,7 +99,7 @@ public: if (charData != NULL) { csound->free(charData); } - charData = csound->strdup(resultString.c_str()); + charData = csound->strdup((char*) resultString.c_str()); charSize = resultString.length() + 1; } break; @@ -128,7 +128,7 @@ public: status = 1; done = true; pending = false; - error = csound->strdup(e.what()); + error = csound->strdup((char*) e.what()); } UNLOCK(connection); } @@ -440,12 +440,12 @@ struct dbexec : csnd::InPlug<2> { LOCK(connection); try { connection->Exec(sql.data); - return OK; } catch (const std::exception &e) { + UNLOCK(connection); return csound->init_error(e.what()); } UNLOCK(connection); - + return OK; } }; @@ -461,14 +461,15 @@ struct dbscalar : csnd::Plugin<1, 4> { return csound->init_error(badHandle); } STRINGDAT &sql = inargs.str_data(1); + LOCK(connection); try { - LOCK(connection); outargs[0] = connection->Scalar(sql.data, inargs[2], inargs[3]); - UNLOCK(connection); - return OK; } catch (const std::exception &e) { + UNLOCK(connection); return csound->init_error(e.what()); - } + } + UNLOCK(connection) + return OK; } }; @@ -486,16 +487,17 @@ struct dbscalarstr : csnd::Plugin<1, 4> { } STRINGDAT &sql = inargs.str_data(1); STRINGDAT &result = outargs.str_data(0); + LOCK(connection); try { - LOCK(connection); std::string resultString = connection->ScalarString(sql.data, inargs[2], inargs[3]); - UNLOCK(connection); result.size = resultString.length() + 1; - result.data = csound->strdup(resultString.c_str()); - return OK; + result.data = csound->strdup((char*)resultString.c_str()); } catch (const std::exception &e) { + UNLOCK(connection); return csound->init_error(e.what()); - } + } + UNLOCK(connection); + return OK; } }; @@ -516,15 +518,16 @@ struct dbarray : csnd::Plugin<1, 2> { STRINGDAT &sql = inargs.str_data(1); ARRAYDAT* array = (ARRAYDAT*) outargs(0); - + LOCK(connection); try { - LOCK(connection); connection->ArrayQuery(sql.data, csound, array); - UNLOCK(connection); return OK; } catch (const std::exception &e) { + UNLOCK(connection); return csound->init_error(e.what()); } + UNLOCK(connection); + return OK; } }; @@ -544,15 +547,15 @@ struct dbarraystr : csnd::Plugin<1, 2> { STRINGDAT &sql = inargs.str_data(1); ARRAYDAT* array = (ARRAYDAT*) outargs(0); - + LOCK(connection); try { - LOCK(connection); connection->ArrayQueryString(sql.data, csound, array); - UNLOCK(connection); - return OK; } catch (const std::exception &e) { + UNLOCK(connection); return csound->init_error(e.what()); } + UNLOCK(connection); + return OK; } }; @@ -579,14 +582,15 @@ struct dbexec_kb : csnd::InPlug<2> { int kperf() { STRINGDAT &sql = args.str_data(1); + LOCK(connection); try { - LOCK(connection); connection->Exec(sql.data); - UNLOCK(connection); - return OK; } catch (const std::exception &e) { + UNLOCK(connection); return csound->perf_error(e.what(), this); } + UNLOCK(connection); + return OK; } }; @@ -606,14 +610,15 @@ struct dbscalar_kb : csnd::Plugin<1, 4> { int kperf() { STRINGDAT &sql = inargs.str_data(1); + LOCK(connection); try { - LOCK(connection); outargs[0] = connection->Scalar(sql.data, inargs[2], inargs[3]); - UNLOCK(connection); - return OK; } catch (const std::exception &e) { + UNLOCK(connection); return csound->perf_error(e.what(), this); } + UNLOCK(connection); + return OK; } }; @@ -636,16 +641,17 @@ struct dbscalarstr_kb : csnd::Plugin<1, 4> { STRINGDAT &sql = inargs.str_data(1); STRINGDAT &result = outargs.str_data(0); + LOCK(connection); try { - LOCK(connection); std::string resultString = connection->ScalarString(sql.data, inargs[2], inargs[3]); - UNLOCK(connection); result.size = resultString.length() + 1; - result.data = csound->strdup(resultString.c_str()); - return OK; + result.data = csound->strdup((char*) resultString.c_str()); } catch (const std::exception &e) { + UNLOCK(connection); return csound->perf_error(e.what(), this); } + UNLOCK(connection); + return OK; } }; @@ -670,15 +676,15 @@ struct dbarray_kb : csnd::Plugin<1, 2> { STRINGDAT &sql = inargs.str_data(1); ARRAYDAT* array = (ARRAYDAT*) outargs(0); - + LOCK(connection); try { - LOCK(connection); connection->ArrayQuery(sql.data, csound, array); - UNLOCK(connection); - return OK; } catch (const std::exception &e) { + UNLOCK(connection); return csound->perf_error(e.what(), this); } + UNLOCK(connection); + return OK; } }; @@ -702,15 +708,15 @@ struct dbarraystr_kb : csnd::Plugin<1, 2> { STRINGDAT &sql = inargs.str_data(1); ARRAYDAT* array = (ARRAYDAT*) outargs(0); - + LOCK(connection); try { - LOCK(connection); connection->ArrayQueryString(sql.data, csound, array); - UNLOCK(connection); - return OK; } catch (const std::exception &e) { + UNLOCK(connection); return csound->perf_error(e.what(), this); } + UNLOCK(connection); + return OK; } }; diff --git a/src/postgresql.cpp b/src/postgresql.cpp index 681c133..882081f 100644 --- a/src/postgresql.cpp +++ b/src/postgresql.cpp @@ -61,7 +61,7 @@ pqxx::result PostgresConnection::Query(char* sql) { return result; } -MYFLT PostgresConnection::Scalar(char* sql, int row=0, int col=0) { +MYFLT PostgresConnection::Scalar(char* sql, int row, int col) { pqxx::result result = Query(sql); // checks as libpqxx not throwing if this happens @@ -75,7 +75,7 @@ MYFLT PostgresConnection::Scalar(char* sql, int row=0, int col=0) { return result[row][col].as<MYFLT>(); } -char* PostgresConnection::ScalarString(char* sql, int row=0, int col=0) { +char* PostgresConnection::ScalarString(char* sql, int row, int col) { pqxx::result result = Query(sql); // checks as libpqxx not throwing if this happens diff --git a/src/sqlite3.cpp b/src/sqlite3.cpp index 824e165..0fd96e3 100644 --- a/src/sqlite3.cpp +++ b/src/sqlite3.cpp @@ -53,7 +53,7 @@ sqlite3_stmt* SqliteConnection::Query(char* sql) { return stmt; } -MYFLT SqliteConnection::Scalar(char* sql, int row=0, int col=0) { +MYFLT SqliteConnection::Scalar(char* sql, int row, int col) { sqlite3_stmt *stmt = Query(sql); int colCount = sqlite3_column_count(stmt); int rc = sqlite3_step(stmt); @@ -76,7 +76,7 @@ MYFLT SqliteConnection::Scalar(char* sql, int row=0, int col=0) { throw std::runtime_error("no result"); } -char* SqliteConnection::ScalarString(char* sql, int row=0, int col=0) { +char* SqliteConnection::ScalarString(char* sql, int row, int col) { sqlite3_stmt *stmt = Query(sql); int colCount = sqlite3_column_count(stmt); int rc = sqlite3_step(stmt); |