diff options
| author | Richard Knight <q@1bpm.net> | 2020-03-17 18:47:36 +0000 | 
|---|---|---|
| committer | Richard Knight <q@1bpm.net> | 2020-03-17 18:47:36 +0000 | 
| commit | c3853f6dd796615f332fefcaaaf563794d867ee4 (patch) | |
| tree | be3aa506a3631e9261a68894a9fad26ccd911f80 /include | |
| download | csound-sqldb-c3853f6dd796615f332fefcaaaf563794d867ee4.tar.gz csound-sqldb-c3853f6dd796615f332fefcaaaf563794d867ee4.tar.bz2 csound-sqldb-c3853f6dd796615f332fefcaaaf563794d867ee4.zip | |
initial
Diffstat (limited to 'include')
| -rw-r--r-- | include/connection.h | 90 | ||||
| -rw-r--r-- | include/logindata.h | 34 | ||||
| -rw-r--r-- | include/mysql.h | 48 | ||||
| -rw-r--r-- | include/postgresql.h | 44 | ||||
| -rw-r--r-- | include/sqlite.h | 44 | 
5 files changed, 260 insertions, 0 deletions
| diff --git a/include/connection.h b/include/connection.h new file mode 100644 index 0000000..e67ea27 --- /dev/null +++ b/include/connection.h @@ -0,0 +1,90 @@ +/* +    connection.h +    Copyright (C) 2019 Richard Knight + + +    This program is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 3 of the License, or (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public License +    along with this program; if not, write to the Free Software Foundation, +    Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. +  + */ + +#ifndef CONNECTION_H +#define CONNECTION_H +#include <plugin.h> +#include "logindata.h" + +#define EXEC 0 +#define SCALAR 1 +#define SCALARSTRING 2 +#define ARRAY 3 +#define ARRAYSTRING 4 + +#define POSTGRES 0 +#define SQLITE 1 +#define MYSQL 2 + +#ifdef BUILD_SQLITE +#include "sqlite.h" +#endif + +#ifdef BUILD_POSTGRES +#include "postgresql.h" +#endif + +#ifdef BUILD_MYSQL +#include "mysql.h" +#endif + + +// tried to do this with templates and inheritance, failed with various approaches  + + + +struct ConnectionData { +    void* mutex; +#ifdef BUILD_SQLITE +    SqliteConnection* sqlite; +#endif +#ifdef BUILD_POSTGRES +    PostgresConnection* postgres; +#endif +#ifdef BUILD_MYSQL +    MySQLConnection* mysql; +#endif +    int type; +    bool open; +    void Init(csnd::Csound* csound, LoginData* login); +    void Close(csnd::Csound* csound); +    void Exec(char* sql); +    MYFLT Scalar(char* sql, int row, int col); +    char* ScalarString(char* sql, int row=0, int col=0); +    void ArrayQuery(char* sql, csnd::Csound* csound, ARRAYDAT* array); +    void ArrayQueryString(char* sql, csnd::Csound* csound, ARRAYDAT* array); +}; + +struct QueryData { +    ConnectionData* connection; +    char* sql; +    int queryType; +    int row; +    int col; +    ARRAYDAT* array; +}; + + + +ConnectionData* getConnection(csnd::Csound* csound, MYFLT handle); + +#endif /* CONNECTION_H */ + diff --git a/include/logindata.h b/include/logindata.h new file mode 100644 index 0000000..8a62e6b --- /dev/null +++ b/include/logindata.h @@ -0,0 +1,34 @@ +/* +    logindata.h +    Copyright (C) 2019 Richard Knight + + +    This program is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 3 of the License, or (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public License +    along with this program; if not, write to the Free Software Foundation, +    Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. +  + */ + +#ifndef LOGINDATA_H +#define LOGINDATA_H + +struct LoginData { +    int dbType; +    char* dbHost; +    char* dbName; +    char* dbUser; +    char* dbPass; +}; + +#endif /* LOGINDATA_H */ + diff --git a/include/mysql.h b/include/mysql.h new file mode 100644 index 0000000..1abc6e3 --- /dev/null +++ b/include/mysql.h @@ -0,0 +1,48 @@ +/* +    mysql.h +    Copyright (C) 2019 Richard Knight + + +    This program is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 3 of the License, or (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public License +    along with this program; if not, write to the Free Software Foundation, +    Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. +  + */ + +#ifndef MYSQL_H +#define MYSQL_H + +#include <plugin.h> +#include <cppconn/driver.h> +#include <cppconn/resultset.h> +#include "connection.h" + +namespace mysql = sql; + +struct MySQLConnection { +    mysql::Driver* driver; +    mysql::Connection* conn; +    void Init(csnd::Csound* csound, LoginData* login); +    void Close(csnd::Csound* csound); +    void Exec(char* sql); +    mysql::ResultSet* Query(char *sql); +    MYFLT Scalar(char* sql, int row, int col); +    char* ScalarString(char* sql, int row, int col); +    void ToArray(mysql::ResultSet* result, csnd::Csound* csound, ARRAYDAT* array, bool asString); +    void ArrayQuery(char* sql, csnd::Csound* csound, ARRAYDAT* array); +    void ArrayQueryString(char* sql, csnd::Csound* csound, ARRAYDAT* array); +}; + + +#endif /* MYSQL_H */ + diff --git a/include/postgresql.h b/include/postgresql.h new file mode 100644 index 0000000..d7db5d9 --- /dev/null +++ b/include/postgresql.h @@ -0,0 +1,44 @@ +/* +    postgresql.h +    Copyright (C) 2019 Richard Knight + + +    This program is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 3 of the License, or (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public License +    along with this program; if not, write to the Free Software Foundation, +    Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. +  + */ + +#ifndef POSTGRESQL_H +#define POSTGRESQL_H + +#include <plugin.h> +#include <pqxx/pqxx>  +#include "connection.h" + +struct PostgresConnection { +    pqxx::connection* conn; +    void Init(csnd::Csound* csound, LoginData* login); +    void Close(csnd::Csound* csound); +    void Exec(char* sql); +    pqxx::result Query(char *sql); +    MYFLT Scalar(char* sql, int row, int col); +    char* ScalarString(char* sql, int row, int col); +    void ToArray(pqxx::result result, csnd::Csound* csound, ARRAYDAT* array, bool asString); +    void ArrayQuery(char* sql, csnd::Csound* csound, ARRAYDAT* array); +    void ArrayQueryString(char* sql, csnd::Csound* csound, ARRAYDAT* array); +}; + + +#endif /* POSTGRESQL_H */ + diff --git a/include/sqlite.h b/include/sqlite.h new file mode 100644 index 0000000..4e2b0c3 --- /dev/null +++ b/include/sqlite.h @@ -0,0 +1,44 @@ +/* +    sqlite.h +    Copyright (C) 2019 Richard Knight + + +    This program is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 3 of the License, or (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public License +    along with this program; if not, write to the Free Software Foundation, +    Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. +  + */ + +#ifndef XSQLITE3_H +#define XSQLITE3_H + +#include <plugin.h> +#include <sqlite3.h> +#include "connection.h" + +struct SqliteConnection { +    sqlite3* conn; +    void Init(csnd::Csound* csound, LoginData* login); +    void Close(csnd::Csound* csound); +    void Exec(char* sql); +    sqlite3_stmt* Query(char *sql); +    MYFLT Scalar(char* sql, int row, int col); +    char* ScalarString(char* sql, int row, int col); +    int RowCount(sqlite3_stmt* stmt); +    void ToArray(sqlite3_stmt* result, csnd::Csound* csound, ARRAYDAT* array, bool asString); +    void ArrayQuery(char* sql, csnd::Csound* csound, ARRAYDAT* array); +    void ArrayQueryString(char* sql, csnd::Csound* csound, ARRAYDAT* array); +}; + +#endif /* SQLITE3_H */ + |