Updated for NWNEE 37-13
Updated for NWNEE 37-13. Updated NWNxEE. Full compile. Updated release archive.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
/// @brief Functions to interface with a database through SQL
|
||||
/// @{
|
||||
/// @file nwnx_sql.nss
|
||||
#include "nwnx"
|
||||
|
||||
const string NWNX_SQL = "NWNX_SQL"; ///< @private
|
||||
|
||||
@@ -61,6 +60,16 @@ void NWNX_SQL_PreparedObjectId(int position, object value);
|
||||
/// @param base64 Use base64-encoded string format if TRUE (default), otherwise use binary format.
|
||||
void NWNX_SQL_PreparedObjectFull(int position, object value, int base64 = TRUE);
|
||||
|
||||
/// @brief Set the NULL value of a prepared statement at given position.
|
||||
/// @param position The nth ? in a prepared statement.
|
||||
void NWNX_SQL_PreparedNULL(int position);
|
||||
|
||||
/// @brief Set the Json value of a prepared statement at given position.
|
||||
/// Convienence function to match other Prepared(type) functions.
|
||||
/// @param position The nth ? in a prepared statement.
|
||||
/// @param value The value to set.
|
||||
void NWNX_SQL_PreparedJson(int position, json value);
|
||||
|
||||
/// @brief Like NWNX_SQL_ReadDataInActiveRow, but for full serialized objects.
|
||||
///
|
||||
/// The object will be deserialized and created in the game. New object ID is returned.
|
||||
@@ -98,23 +107,23 @@ string NWNX_SQL_GetLastError();
|
||||
/// @return Returns the number of parameters expected by the prepared query or -1 if no query is prepared.
|
||||
int NWNX_SQL_GetPreparedQueryParamCount();
|
||||
|
||||
/// @brief Set the next query to return full binary results **ON THE FIRST COLUMN ONLY**.
|
||||
/// @note This is ONLY needed on PostgreSQL, and ONLY if you want to deserialize raw bytea in NWNX_SQL_ReadFullObjectInActiveRow with base64=FALSE.
|
||||
void NWNX_SQL_PostgreSQL_SetNextQueryResultsBinaryMode();
|
||||
|
||||
/// @}
|
||||
|
||||
int NWNX_SQL_PrepareQuery(string query)
|
||||
{
|
||||
string sFunc = "PrepareQuery";
|
||||
|
||||
NWNX_PushArgumentString(NWNX_SQL, sFunc, query);
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
return NWNX_GetReturnValueInt(NWNX_SQL, sFunc);
|
||||
NWNXPushString(query);
|
||||
NWNXCall(NWNX_SQL, "PrepareQuery");
|
||||
return NWNXPopInt();
|
||||
}
|
||||
|
||||
int NWNX_SQL_ExecutePreparedQuery()
|
||||
{
|
||||
string sFunc = "ExecutePreparedQuery";
|
||||
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
return NWNX_GetReturnValueInt(NWNX_SQL, sFunc);
|
||||
NWNXCall(NWNX_SQL, "ExecutePreparedQuery");
|
||||
return NWNXPopInt();
|
||||
}
|
||||
|
||||
int NWNX_SQL_ExecuteQuery(string query)
|
||||
@@ -132,123 +141,109 @@ int NWNX_SQL_ExecuteQuery(string query)
|
||||
|
||||
int NWNX_SQL_ReadyToReadNextRow()
|
||||
{
|
||||
string sFunc = "ReadyToReadNextRow";
|
||||
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
return NWNX_GetReturnValueInt(NWNX_SQL, sFunc);
|
||||
NWNXCall(NWNX_SQL, "ReadyToReadNextRow");
|
||||
return NWNXPopInt();
|
||||
}
|
||||
|
||||
void NWNX_SQL_ReadNextRow()
|
||||
{
|
||||
string sFunc = "ReadNextRow";
|
||||
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
NWNXCall(NWNX_SQL, "ReadNextRow");
|
||||
}
|
||||
|
||||
string NWNX_SQL_ReadDataInActiveRow(int column = 0)
|
||||
{
|
||||
string sFunc = "ReadDataInActiveRow";
|
||||
|
||||
NWNX_PushArgumentInt(NWNX_SQL, sFunc, column);
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
return NWNX_GetReturnValueString(NWNX_SQL, sFunc);
|
||||
NWNXPushInt(column);
|
||||
NWNXCall(NWNX_SQL, "ReadDataInActiveRow");
|
||||
return NWNXPopString();
|
||||
}
|
||||
|
||||
|
||||
void NWNX_SQL_PreparedInt(int position, int value)
|
||||
{
|
||||
string sFunc = "PreparedInt";
|
||||
|
||||
NWNX_PushArgumentInt(NWNX_SQL, sFunc, value);
|
||||
NWNX_PushArgumentInt(NWNX_SQL, sFunc, position);
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
NWNXPushInt(value);
|
||||
NWNXPushInt(position);
|
||||
NWNXCall(NWNX_SQL, "PreparedInt");
|
||||
}
|
||||
void NWNX_SQL_PreparedString(int position, string value)
|
||||
{
|
||||
string sFunc = "PreparedString";
|
||||
|
||||
NWNX_PushArgumentString(NWNX_SQL, sFunc, value);
|
||||
NWNX_PushArgumentInt(NWNX_SQL, sFunc, position);
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
|
||||
NWNXPushString(value);
|
||||
NWNXPushInt(position);
|
||||
NWNXCall(NWNX_SQL, "PreparedString");
|
||||
}
|
||||
void NWNX_SQL_PreparedFloat(int position, float value)
|
||||
{
|
||||
string sFunc = "PreparedFloat";
|
||||
|
||||
NWNX_PushArgumentFloat(NWNX_SQL, sFunc, value);
|
||||
NWNX_PushArgumentInt(NWNX_SQL, sFunc, position);
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
|
||||
NWNXPushFloat(value);
|
||||
NWNXPushInt(position);
|
||||
NWNXCall(NWNX_SQL, "PreparedFloat");
|
||||
}
|
||||
void NWNX_SQL_PreparedObjectId(int position, object value)
|
||||
{
|
||||
string sFunc = "PreparedObjectId";
|
||||
|
||||
NWNX_PushArgumentObject(NWNX_SQL, sFunc, value);
|
||||
NWNX_PushArgumentInt(NWNX_SQL, sFunc, position);
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
|
||||
NWNXPushObject(value);
|
||||
NWNXPushInt(position);
|
||||
NWNXCall(NWNX_SQL, "PreparedObjectId");
|
||||
}
|
||||
void NWNX_SQL_PreparedObjectFull(int position, object value, int base64 = TRUE)
|
||||
{
|
||||
string sFunc = "PreparedObjectFull";
|
||||
|
||||
NWNX_PushArgumentInt(NWNX_SQL, sFunc, base64);
|
||||
NWNX_PushArgumentObject(NWNX_SQL, sFunc, value);
|
||||
NWNX_PushArgumentInt(NWNX_SQL, sFunc, position);
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
NWNXPushInt(base64);
|
||||
NWNXPushObject(value);
|
||||
NWNXPushInt(position);
|
||||
NWNXCall(NWNX_SQL, "PreparedObjectFull");
|
||||
}
|
||||
void NWNX_SQL_PreparedNULL(int position)
|
||||
{
|
||||
NWNXPushInt(position);
|
||||
NWNXCall(NWNX_SQL, "PreparedNULL");
|
||||
}
|
||||
void NWNX_SQL_PreparedJson(int position, json value)
|
||||
{
|
||||
// Dump to string and continue as a string from here.
|
||||
// Famously assuming we're sent valid Json here.
|
||||
NWNX_SQL_PreparedString(position, JsonDump(value));
|
||||
}
|
||||
|
||||
|
||||
object NWNX_SQL_ReadFullObjectInActiveRow(int column = 0, object owner = OBJECT_INVALID, float x = 0.0, float y = 0.0, float z = 0.0, int base64 = TRUE)
|
||||
{
|
||||
string sFunc = "ReadFullObjectInActiveRow";
|
||||
|
||||
NWNX_PushArgumentInt(NWNX_SQL, sFunc, base64);
|
||||
NWNX_PushArgumentFloat(NWNX_SQL, sFunc, z);
|
||||
NWNX_PushArgumentFloat(NWNX_SQL, sFunc, y);
|
||||
NWNX_PushArgumentFloat(NWNX_SQL, sFunc, x);
|
||||
NWNX_PushArgumentObject(NWNX_SQL, sFunc, owner);
|
||||
NWNX_PushArgumentInt(NWNX_SQL, sFunc, column);
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
return NWNX_GetReturnValueObject(NWNX_SQL, sFunc);
|
||||
NWNXPushInt(base64);
|
||||
NWNXPushFloat(z);
|
||||
NWNXPushFloat(y);
|
||||
NWNXPushFloat(x);
|
||||
NWNXPushObject(owner);
|
||||
NWNXPushInt(column);
|
||||
NWNXCall(NWNX_SQL, "ReadFullObjectInActiveRow");
|
||||
return NWNXPopObject();
|
||||
}
|
||||
|
||||
int NWNX_SQL_GetAffectedRows()
|
||||
{
|
||||
string sFunc = "GetAffectedRows";
|
||||
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
return NWNX_GetReturnValueInt(NWNX_SQL, sFunc);
|
||||
NWNXCall(NWNX_SQL, "GetAffectedRows");
|
||||
return NWNXPopInt();
|
||||
}
|
||||
|
||||
string NWNX_SQL_GetDatabaseType()
|
||||
{
|
||||
string sFunc = "GetDatabaseType";
|
||||
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
return NWNX_GetReturnValueString(NWNX_SQL, sFunc);
|
||||
NWNXCall(NWNX_SQL, "GetDatabaseType");
|
||||
return NWNXPopString();
|
||||
}
|
||||
|
||||
void NWNX_SQL_DestroyPreparedQuery()
|
||||
{
|
||||
string sFunc = "DestroyPreparedQuery";
|
||||
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
NWNXCall(NWNX_SQL, "DestroyPreparedQuery");
|
||||
}
|
||||
|
||||
string NWNX_SQL_GetLastError()
|
||||
{
|
||||
string sFunc = "GetLastError";
|
||||
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
return NWNX_GetReturnValueString(NWNX_SQL, sFunc);
|
||||
NWNXCall(NWNX_SQL, "GetLastError");
|
||||
return NWNXPopString();
|
||||
}
|
||||
|
||||
int NWNX_SQL_GetPreparedQueryParamCount()
|
||||
{
|
||||
string sFunc = "GetPreparedQueryParamCount";
|
||||
|
||||
NWNX_CallFunction(NWNX_SQL, sFunc);
|
||||
return NWNX_GetReturnValueInt(NWNX_SQL, sFunc);
|
||||
NWNXCall(NWNX_SQL, "GetPreparedQueryParamCount");
|
||||
return NWNXPopInt();
|
||||
}
|
||||
|
||||
void NWNX_SQL_PostgreSQL_SetNextQueryResultsBinaryMode()
|
||||
{
|
||||
NWNXCall(NWNX_SQL, "PostgreSQL_SetNextQueryResultsBinaryMode");
|
||||
}
|
||||
|
Reference in New Issue
Block a user