diff --git a/include/sqlset.cpp b/include/sqlset.cpp index a695eba68..4ad310867 100755 --- a/include/sqlset.cpp +++ b/include/sqlset.cpp @@ -63,10 +63,10 @@ sqlite3* TSQLite::open(const char* fname) _currdb = fname; int err = sqlite3_open(_currdb, &_handle); - if (err = SQLITE_CORRUPT) + if (err == SQLITE_CORRUPT) { close(); - xvt_fsys_remove_file(_currdb); + _currdb.fremove(); err = sqlite3_open(_currdb, &_handle); } @@ -149,15 +149,15 @@ bool TSQLite::set_dbf_time(const TString& table, long last) static int dbf_time_callback(void* jolly, int argc, char** argv, char** columns) { - long& last = *(long*)jolly; - last = atol(argv[0]); + long* last = (long*)jolly; + *last = atol(argv[0]); return SQLITE_OK; } long TSQLite::get_dbf_time(const TString& table) { TString sql; - sql << "SELECT time FROM " << DBF_TIMES_TABLE << "\nWHERE name='" << table << "';"; + sql << "SELECT time FROM " << DBF_TIMES_TABLE << " WHERE name='" << table << "';"; long last = 0; exec(sql, dbf_time_callback, &last); return last; @@ -212,7 +212,7 @@ bool TSQLite::bind_record(const TRectype& rec, const RecDes& rd, sqlite3_stmt* p { int rc = SQLITE_OK; TVariant tmp; - for (int i = 0; i < rd.NFields && rc==SQLITE_OK ; i++) + for (int i = 0; i < rd.NFields && rc==SQLITE_OK; i++) { get_sql_value(rec, rd.Fd[i], tmp); const TString& val = tmp.as_string(); @@ -226,9 +226,9 @@ bool TSQLite::import(int logicnum) const TString& table = logic2table(logicnum); long last = get_dbf_time(table); - if (logicnum >= LF_USER) // Dummy test + if (logicnum >= LF_USER) // Dummy test, 'last' should be updated ALWAYS! { - TLocalisamfile file(logicnum); + TBaseisamfile file(logicnum); if (!file.is_changed_since(last)) return true; } @@ -337,12 +337,19 @@ bool TSQLite::parse_select_from(const char* szSql) if (from < 0) return false; - const int where = sql.find("WHERE", from); - TToken_string tables(sql.sub(from+5, where), ','); + const int where_pos = sql.find("WHERE", from); + TToken_string tables(sql.sub(from+5, where_pos), ','); TString table; FOR_EACH_TOKEN(tables, tok) { table = tok; + const int join_pos = table.find("JOIN "); + if (join_pos > 0) + { + const TString& joined = table.mid(join_pos+5).before(' '); + tables.add(joined); + table = table.before(' '); + } table.trim(); for (int i = 0; table[i]; i++) { @@ -351,8 +358,7 @@ bool TSQLite::parse_select_from(const char* szSql) } const int logicnum = (table == "MAG") ? LF_MAG : table2logic(table); - - if (logicnum > 0) + if (logicnum >= LF_USER) import(logicnum); } @@ -415,6 +421,7 @@ int TSQL_recordset::on_get_items(int argc, char** values, char** columns) } if (_items < _pagesize) { + // Aggiusta le lunghezze dei campi testo e numerici for (int i = 0; i < argc; i++) if (values[i] && *values[i]) { TRecordset_column_info& info = (TRecordset_column_info&)_column[i];