Patch level : 12.0 1028

Files correlati     : xvaga.dll
Commento :

Aggiunta funzione xvt_sql_field_type
This commit is contained in:
Alessandro Bonazzi 2021-01-21 23:13:11 +01:00
parent 5f2800d57b
commit b29de6e86c
2 changed files with 43 additions and 0 deletions

View File

@ -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);

View File

@ -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;