NWNX:EE  8193.36.12
nwnx_sql.nss
Go to the documentation of this file.
1 #include "nwnx"
6 
7 const string NWNX_SQL = "NWNX_SQL";
8 
13 int NWNX_SQL_PrepareQuery(string query);
14 
18 
22 int NWNX_SQL_ExecuteQuery(string query);
23 
27 
32 
36 string NWNX_SQL_ReadDataInActiveRow(int column = 0);
37 
41 void NWNX_SQL_PreparedInt(int position, int value);
42 
46 void NWNX_SQL_PreparedString(int position, string value);
47 
51 void NWNX_SQL_PreparedFloat(int position, float value);
52 
56 void NWNX_SQL_PreparedObjectId(int position, object value);
57 
62 void NWNX_SQL_PreparedObjectFull(int position, object value, int base64 = TRUE);
63 
66 void NWNX_SQL_PreparedNULL(int position);
67 
72 void NWNX_SQL_PreparedJson(int position, json value);
73 
88 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);
89 
94 
99 
103 
105 string NWNX_SQL_GetLastError();
106 
110 
114 
116 
117 int NWNX_SQL_PrepareQuery(string query)
118 {
119  string sFunc = "PrepareQuery";
120 
122  NWNX_CallFunction(NWNX_SQL, sFunc);
123  return NWNX_GetReturnValueInt();
124 }
125 
127 {
128  string sFunc = "ExecutePreparedQuery";
129 
130  NWNX_CallFunction(NWNX_SQL, sFunc);
131  return NWNX_GetReturnValueInt();
132 }
133 
134 int NWNX_SQL_ExecuteQuery(string query)
135 {
136  // Note: the implementation might change as support for more SQL targets arrives.
137  if (NWNX_SQL_PrepareQuery(query))
138  {
139  int ret = NWNX_SQL_ExecutePreparedQuery();
141  return ret;
142  }
143 
144  return FALSE;
145 }
146 
148 {
149  string sFunc = "ReadyToReadNextRow";
150 
151  NWNX_CallFunction(NWNX_SQL, sFunc);
152  return NWNX_GetReturnValueInt();
153 }
154 
156 {
157  string sFunc = "ReadNextRow";
158 
159  NWNX_CallFunction(NWNX_SQL, sFunc);
160 }
161 
162 string NWNX_SQL_ReadDataInActiveRow(int column = 0)
163 {
164  string sFunc = "ReadDataInActiveRow";
165 
166  NWNX_PushArgumentInt(column);
167  NWNX_CallFunction(NWNX_SQL, sFunc);
168  return NWNX_GetReturnValueString();
169 }
170 
171 
172 void NWNX_SQL_PreparedInt(int position, int value)
173 {
174  string sFunc = "PreparedInt";
175 
176  NWNX_PushArgumentInt(value);
177  NWNX_PushArgumentInt(position);
178  NWNX_CallFunction(NWNX_SQL, sFunc);
179 }
180 void NWNX_SQL_PreparedString(int position, string value)
181 {
182  string sFunc = "PreparedString";
183 
185  NWNX_PushArgumentInt(position);
186  NWNX_CallFunction(NWNX_SQL, sFunc);
187 }
188 void NWNX_SQL_PreparedFloat(int position, float value)
189 {
190  string sFunc = "PreparedFloat";
191 
192  NWNX_PushArgumentFloat(value);
193  NWNX_PushArgumentInt(position);
194  NWNX_CallFunction(NWNX_SQL, sFunc);
195 }
196 void NWNX_SQL_PreparedObjectId(int position, object value)
197 {
198  string sFunc = "PreparedObjectId";
199 
201  NWNX_PushArgumentInt(position);
202  NWNX_CallFunction(NWNX_SQL, sFunc);
203 }
204 void NWNX_SQL_PreparedObjectFull(int position, object value, int base64 = TRUE)
205 {
206  string sFunc = "PreparedObjectFull";
207 
208  NWNX_PushArgumentInt(base64);
210  NWNX_PushArgumentInt(position);
211  NWNX_CallFunction(NWNX_SQL, sFunc);
212 }
213 void NWNX_SQL_PreparedNULL(int position)
214 {
215  string sFunc = "PreparedNULL";
216 
217  NWNX_PushArgumentInt(position);
218  NWNX_CallFunction(NWNX_SQL, sFunc);
219 }
220 void NWNX_SQL_PreparedJson(int position, json value)
221 {
222  // Dump to string and continue as a string from here.
223  // Famously assuming we're sent valid Json here.
224  NWNX_SQL_PreparedString(position, JsonDump(value));
225 }
226 
227 
228 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)
229 {
230  string sFunc = "ReadFullObjectInActiveRow";
231 
232  NWNX_PushArgumentInt(base64);
237  NWNX_PushArgumentInt(column);
238  NWNX_CallFunction(NWNX_SQL, sFunc);
239  return NWNX_GetReturnValueObject();
240 }
241 
243 {
244  string sFunc = "GetAffectedRows";
245 
246  NWNX_CallFunction(NWNX_SQL, sFunc);
247  return NWNX_GetReturnValueInt();
248 }
249 
251 {
252  string sFunc = "GetDatabaseType";
253 
254  NWNX_CallFunction(NWNX_SQL, sFunc);
255  return NWNX_GetReturnValueString();
256 }
257 
259 {
260  string sFunc = "DestroyPreparedQuery";
261 
262  NWNX_CallFunction(NWNX_SQL, sFunc);
263 }
264 
266 {
267  string sFunc = "GetLastError";
268 
269  NWNX_CallFunction(NWNX_SQL, sFunc);
270  return NWNX_GetReturnValueString();
271 }
272 
274 {
275  string sFunc = "GetPreparedQueryParamCount";
276 
277  NWNX_CallFunction(NWNX_SQL, sFunc);
278  return NWNX_GetReturnValueInt();
279 }
280 
282 {
283  string sFunc = "PostgreSQL_SetNextQueryResultsBinaryMode";
284 
285  NWNX_CallFunction(NWNX_SQL, sFunc);
286 }
NWNX_SQL_PreparedJson
void NWNX_SQL_PreparedJson(int position, json value)
Set the Json value of a prepared statement at given position. Convienence function to match other Pre...
Definition: nwnx_sql.nss:220
NWNX_SQL_ExecutePreparedQuery
int NWNX_SQL_ExecutePreparedQuery()
Executes a query which has been prepared.
Definition: nwnx_sql.nss:126
NWNX_SQL_PreparedInt
void NWNX_SQL_PreparedInt(int position, int value)
Set the int value of a prepared statement at given position.
Definition: nwnx_sql.nss:172
NWNX_GetReturnValueInt
int NWNX_GetReturnValueInt()
Returns the specified type from the c++ side.
Definition: nwnx.nss:94
NWNX_SQL_GetAffectedRows
int NWNX_SQL_GetAffectedRows()
Gets the rows affected by a query.
Definition: nwnx_sql.nss:242
NWNX_SQL_PreparedNULL
void NWNX_SQL_PreparedNULL(int position)
Set the NULL value of a prepared statement at given position.
Definition: nwnx_sql.nss:213
NWNX_SQL_PreparedObjectFull
void NWNX_SQL_PreparedObjectFull(int position, object value, int base64=TRUE)
Set the full serialized object value of a prepared statement at given position.
Definition: nwnx_sql.nss:204
NWNX_SQL_PostgreSQL_SetNextQueryResultsBinaryMode
void NWNX_SQL_PostgreSQL_SetNextQueryResultsBinaryMode()
Set the next query to return full binary results ON THE FIRST COLUMN ONLY.
Definition: nwnx_sql.nss:281
NWNX_SQL_PreparedFloat
void NWNX_SQL_PreparedFloat(int position, float value)
Set the float value of a prepared statement at given position.
Definition: nwnx_sql.nss:188
NWNX_SQL_ReadNextRow
void NWNX_SQL_ReadNextRow()
Reads the next row of returned data.
Definition: nwnx_sql.nss:155
NWNX_SQL_PrepareQuery
int NWNX_SQL_PrepareQuery(string query)
Prepares the provided query for execution.
Definition: nwnx_sql.nss:117
NWNX_CallFunction
void NWNX_CallFunction(string pluginName, string functionName)
Scripting interface to NWNX.
Definition: nwnx.nss:54
NWNX_GetReturnValueString
string NWNX_GetReturnValueString()
Returns the specified type from the c++ side.
Definition: nwnx.nss:109
NWNX_SQL_PreparedObjectId
void NWNX_SQL_PreparedObjectId(int position, object value)
Set the ObjectId value of a prepared statement at given position.
Definition: nwnx_sql.nss:196
NWNX_PushArgumentString
void NWNX_PushArgumentString(string value)
Pushes the specified type to the c++ side.
Definition: nwnx.nss:74
NWNX_SQL_ExecuteQuery
int NWNX_SQL_ExecuteQuery(string query)
Directly execute an SQL query.
Definition: nwnx_sql.nss:134
NWNX_SQL_ReadDataInActiveRow
string NWNX_SQL_ReadDataInActiveRow(int column=0)
Definition: nwnx_sql.nss:162
NWNX_PushArgumentObject
void NWNX_PushArgumentObject(object value)
Pushes the specified type to the c++ side.
Definition: nwnx.nss:69
NWNX_SQL_ReadFullObjectInActiveRow
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)
Like NWNX_SQL_ReadDataInActiveRow, but for full serialized objects.
Definition: nwnx_sql.nss:228
NWNX_PushArgumentInt
void NWNX_PushArgumentInt(int value)
Pushes the specified type to the c++ side.
Definition: nwnx.nss:59
NWNX_SQL_ReadyToReadNextRow
int NWNX_SQL_ReadyToReadNextRow()
Definition: nwnx_sql.nss:147
NWNX_SQL_GetDatabaseType
string NWNX_SQL_GetDatabaseType()
Definition: nwnx_sql.nss:250
NWNX_GetReturnValueObject
object NWNX_GetReturnValueObject()
Returns the specified type from the c++ side.
Definition: nwnx.nss:104
NWNX_SQL_GetPreparedQueryParamCount
int NWNX_SQL_GetPreparedQueryParamCount()
Gets the number of parameteres expected by a prepared query.
Definition: nwnx_sql.nss:273
NWNX_SQL_PreparedString
void NWNX_SQL_PreparedString(int position, string value)
Set the string value of a prepared statement at given position.
Definition: nwnx_sql.nss:180
NWNX_SQL_DestroyPreparedQuery
void NWNX_SQL_DestroyPreparedQuery()
Free any resources attached to an existing prepared query.
Definition: nwnx_sql.nss:258
NWNX_SQL_GetLastError
string NWNX_SQL_GetLastError()
Definition: nwnx_sql.nss:265
NWNX_PushArgumentFloat
void NWNX_PushArgumentFloat(float value)
Pushes the specified type to the c++ side.
Definition: nwnx.nss:64