@@ -114,6 +114,7 @@ int Database::GenericAccess(IFunctionHandler* pH, const AccessType action, const
114114 {
115115 case AccessType::Set:
116116 cache[key] = value;
117+ LogDebug (isGlobal ? " Set Global %s = %s" : " Set %s = %s" , key, FormatAnyValue (value));
117118 if (isGlobal)
118119 {
119120 m_globalDirty = true ;
@@ -127,6 +128,7 @@ int Database::GenericAccess(IFunctionHandler* pH, const AccessType action, const
127128 case AccessType::Del:
128129 {
129130 const bool erased = cache.erase (key) > 0 ;
131+ LogDebug (isGlobal ? " Delete Global %s: %s" : " Delete %s: %s" , key, erased ? " OK" : " Not found" );
130132 if (isGlobal && erased)
131133 {
132134 m_globalDirty = true ;
@@ -194,10 +196,9 @@ void Database::OnPostUpdate(float /*fDeltaTime*/)
194196 if (!m_globalDirty) return ;
195197 if (const auto now = steady_clock::now (); now - m_lastSaveTime < SAVE_INTERVAL) return ;
196198
197- int successCount = 0 ;
198-
199199 try
200200 {
201+ int successCount = 0 ;
201202 ExecuteTransaction ([this , &successCount](const SQLite::Database& db)
202203 {
203204 SQLite::Statement clearStmt (db, " DELETE FROM Store WHERE savefile = ''" );
@@ -279,32 +280,17 @@ int Database::BatchOperation(SQLite::Database& db, const Cache& cache, const std
279280
280281std::optional<ScriptAnyValue> Database::ParseAnyValue (const int type, const std::string& value)
281282{
282- ScriptAnyValue any;
283283 switch (type)
284284 {
285285 case ANY_TBOOLEAN:
286- {
287- any.type = ANY_TBOOLEAN;
288- any.b = std::stoi (value) != 0 ;
289- }
290- break ;
286+ return ScriptAnyValue (std::stoi (value) != 0 );
291287 case ANY_TNUMBER:
292- {
293- any.type = ANY_TNUMBER;
294- any.number = std::stod (value);
295- }
296- break ;
288+ return ScriptAnyValue (std::stof (value));
297289 case ANY_TSTRING:
298- {
299- any.type = ANY_TSTRING;
300- // Fix for string encoding issues - ensure we properly handle UTF-8 strings
301- any.str = _strdup (value.c_str ());
302- }
303- break ;
290+ return ScriptAnyValue (_strdup (value.c_str ()));
304291 default :
305292 return std::nullopt ;
306293 }
307- return any;
308294}
309295
310296std::optional<std::string> Database::SerializeAnyValue (const ScriptAnyValue& any)
@@ -318,15 +304,32 @@ std::optional<std::string> Database::SerializeAnyValue(const ScriptAnyValue& any
318304 case ANY_TSTRING:
319305 {
320306 if (!any.str ) return " " ;
321-
322- // Return the string directly - SQLite handles UTF-8 text natively
323307 return std::string (any.str );
324308 }
325309 default :
326310 return std::nullopt ;
327311 }
328312}
329313
314+ const char * Database::FormatAnyValue (const ScriptAnyValue& value)
315+ {
316+ switch (value.type )
317+ {
318+ case ANY_TNUMBER: return std::to_string (value.number ).c_str ();
319+ case ANY_TSTRING: return value.str ;
320+ case ANY_TBOOLEAN: return value.b ? " true" : " false" ;
321+ case ANY_TTABLE: return " [Table]" ;
322+ case ANY_TNIL: return " [Nil]" ;
323+ case ANY_TFUNCTION: return " [Function]" ;
324+ case ANY_TUSERDATA: return " [UserData]" ;
325+ case ANY_TVECTOR: return " [Vector]" ;
326+ case ANY_COUNT: return " [Count]" ;
327+ case ANY_THANDLE: return " [Handle]" ;
328+ case ANY_ANY: return " [Any]" ;
329+ default : return " [Unknown]" ;
330+ }
331+ }
332+
330333int Database::Dump (IFunctionHandler* pH)
331334{
332335 std::lock_guard lock (m_mutex);
0 commit comments