Aller au contenu

Photo

Simple SQL Query Returns No Data


  • Veuillez vous connecter pour répondre
4 réponses à ce sujet

#1
BelowTheBelt

BelowTheBelt
  • Members
  • 394 messages

I must be missing something very basic, but it's stymied me for a couple of days and I need to figure this out.

 

I have a general table that holds module-level data, called mod_main.  One  of the columns there is "InGameDate" and is a varchar type (50 chars wide).

 

OnModuleLoad, I make two function calls regarding this field:

 

1)  GetDate to retrieve the string from the InGameDate field with:

SQLExecDirect("SELECT InGameDate FROM mod_main");
string sDate = SQLGetData(1);
WriteTimestampedLogEntry ("GetDate = "+sDate);
 
and
 
2)  SaveDate to save a new date into the InGameDate field with a date iValue:
SQLExecDirect("UPDATE mod_main SET InGameDate ='"+IntToString(iValue)+"'");
WriteTimestampedLogEntry ("SetDate = "+IntToString(iValue));

Seems easy enough.

 

However, when I look at my logfile here's what I get:

 

[Tue Nov 18 19:48:19] GetDate = 
[Tue Nov 18 19:48:19] SetDate = 11072527
 
As you can see, the SetDate is accurate and it is writing/updating the database (This is a mathmatically-arrived value of the year, month, day, and hour).  I've verified that it is writing correctly to the db.  But, the GetDate string is empty.  Even when I set this on a looping delay timer pseudo hb, the GetDate continues to be blank, while the SetDate continues to update correctly.
 
I've tried modifying the InGameDate column to text format (from varchar) to no avail.
 
Additionally, when I run the GetDate query directly in SQL, it properly returns the value of the field.
 
Any thoughts?


#2
meaglyn

meaglyn
  • Members
  • 813 messages

I believe you need to call SQLFetch() before SQLGetData().



#3
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

I recommend you first check if query returned no result.
 
this way should work 

string sSQL = "SELECT InGameDate FROM mod_main";
PrintString("Executing query: " + sSQL);
SQLExecDirect(sSQL);

string sDate = "";

if (SQLFetch() != SQL_SUCCESS)
{
PrintString("Could not execute the query or query returned no result.");
return; //stops the current script, you may delete here if you want
}
else
{
sDate = SQLGetData(1);
PrintString("GetDate = "+sDate);
}


#4
BelowTheBelt

BelowTheBelt
  • Members
  • 394 messages

Thanks.  I was presuming the SQLFetch was optional to validate that the data found (or not) or to return the next row.  Didn't realize it was required.  Put it in and it works.



#5
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

Good you got it. (:

Oh, what are you trying to do with game time?