From b29de6e86c7d5abbd4f484d095c3d8c45f2fe64b Mon Sep 17 00:00:00 2001 From: Alessandro Bonazzi Date: Thu, 21 Jan 2021 23:13:11 +0100 Subject: [PATCH] Patch level : 12.0 1028 Files correlati : xvaga.dll Commento : Aggiunta funzione xvt_sql_field_type --- src/xvaga/xvt.h | 1 + src/xvaga/xvt_sql.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/xvaga/xvt.h b/src/xvaga/xvt.h index 938a894c9..df04a8436 100755 --- a/src/xvaga/xvt.h +++ b/src/xvaga/xvt.h @@ -520,6 +520,7 @@ XVTDLL BOOLEAN xvt_sql_driver(XVT_SQLDB handle, char* str, int max_size); XVTDLL ULONG xvt_sql_execute(XVT_SQLDB handle, const char* sql, ODBC_CALLBACK cb, void* jolly); XVTDLL SLIST xvt_sql_list_fields(XVT_SQLDB handle, const char* table); XVTDLL SLIST xvt_sql_list_tables(XVT_SQLDB handle); +XVTDLL const char * xvt_sql_field_type(XVT_SQLDB handle, const char* table, const char* field); XVTDLL XVT_SQLDB xvt_sql_open(const char* dsn, const char* usr, const char* pwd, const char* dir); XVTDLL BOOLEAN xvt_sql_rollback(XVT_SQLDB handle); XVTDLL BOOLEAN xvt_sql_table_exists(XVT_SQLDB handle, const char* name); diff --git a/src/xvaga/xvt_sql.cpp b/src/xvaga/xvt_sql.cpp index 82fcb2beb..3477e8053 100644 --- a/src/xvaga/xvt_sql.cpp +++ b/src/xvaga/xvt_sql.cpp @@ -12,6 +12,7 @@ public: virtual ULONG Execute(const char* sql, ODBC_CALLBACK cb, void* jolly) = 0; virtual SLIST ListFields(const char* table) const = 0; virtual SLIST ListTables() const = 0; + virtual wxString FindField(const char* strTable, const char* strField) const = 0; virtual bool TableExists(const char* name) const; virtual bool Begin() const { return false; } @@ -46,6 +47,8 @@ protected: virtual ULONG Execute(const char* sql, ODBC_CALLBACK cb, void* jolly); virtual SLIST ListFields(const char* table) const; virtual SLIST ListTables() const; + virtual wxString FindField(const char* strTable, const char* strField) const; + virtual bool TableExists(const char* name) const; public: @@ -245,6 +248,32 @@ SLIST XVT_SQLDB_SQLite3::ListFields(const char* strTable) const return list; } +wxString XVT_SQLDB_SQLite3::FindField(const char* strTable, const char* strField) const +{ + wxString strType; + + if (TableExists(strTable)) + { + wxString strQuery; strQuery << "PRAGMA table_info(" << (const char*)strTable << ");"; + try + { + wxSQLite3ResultSet rs = m_pDB->ExecuteQuery(strQuery); + while (rs.NextRow()) + { + const wxString strFieldFound = rs.GetAsString(1); + + if (strFieldFound == strField) + strType = rs.GetAsString(2); + } + } + catch (wxSQLite3Exception& e) + { + xvt_dm_post_error(e.GetMessage() + "\n" + strQuery); + } + } + return strType; +} + bool XVT_SQLDB_SQLite3::TableExists(const char* name) const { return m_pDB != NULL && name && *name && m_pDB->TableExists(name); @@ -349,6 +378,19 @@ SLIST xvt_sql_list_tables(XVT_SQLDB handle) return list; } +XVTDLL const char * xvt_sql_field_type(XVT_SQLDB handle, const char* table, const char* field) +{ + XVT_SQLDataBase* db = (XVT_SQLDataBase*)handle; + static wxString strType; + + strType = ""; + if (db != NULL && db->IsOk()) + strType = db->FindField(table, field); + + return strType; +} + + BOOLEAN xvt_sql_table_exists(XVT_SQLDB handle, const char* name) { BOOLEAN yes = FALSE;