|
NWNX:EE
8193.36.12
|
|
Go to the documentation of this file.
20 string Array_At_Str(
string tag,
int index,
object obj=OBJECT_INVALID);
21 float Array_At_Flt(
string tag,
int index,
object obj=OBJECT_INVALID);
22 int Array_At_Int(
string tag,
int index,
object obj=OBJECT_INVALID);
23 object Array_At_Obj(
string tag,
int index,
object obj=OBJECT_INVALID);
28 void Array_Clear(
string tag,
object obj=OBJECT_INVALID);
45 void Array_Copy(
string tag,
string otherTag,
object obj=OBJECT_INVALID);
48 void Array_Erase(
string tag,
int index,
object obj=OBJECT_INVALID);
58 int Array_Find_Flt(
string tag,
float element,
object obj=OBJECT_INVALID);
59 int Array_Find_Int(
string tag,
int element,
object obj=OBJECT_INVALID);
60 int Array_Find_Obj(
string tag,
object element,
object obj=OBJECT_INVALID);
61 int Array_Find_Str(
string tag,
string element,
object obj=OBJECT_INVALID);
72 void Array_Insert_Flt(
string tag,
int index,
float element,
object obj=OBJECT_INVALID);
73 void Array_Insert_Int(
string tag,
int index,
int element,
object obj=OBJECT_INVALID);
74 void Array_Insert_Obj(
string tag,
int index,
object element,
object obj=OBJECT_INVALID);
75 void Array_Insert_Str(
string tag,
int index,
string element,
object obj=OBJECT_INVALID);
93 void Array_Resize(
string tag,
int size,
object obj=OBJECT_INVALID);
99 int Array_Size(
string tag,
object obj=OBJECT_INVALID);
115 void Array_Set_Flt(
string tag,
int index,
float element,
object obj=OBJECT_INVALID);
116 void Array_Set_Int(
string tag,
int index,
int element,
object obj=OBJECT_INVALID);
117 void Array_Set_Obj(
string tag,
int index,
object element,
object obj=OBJECT_INVALID);
118 void Array_Set_Str(
string tag,
int index,
string element,
object obj=OBJECT_INVALID);
126 string GetTableName(
string tag,
object obj=OBJECT_INVALID,
int bare=FALSE) {
127 if (obj == OBJECT_INVALID)
130 string sName =
"array_" + ObjectToString(obj) +
"_" + tag;
132 string sCleansed = RegExpReplace(
"[^A-Za-z0-9_\$@#]", sName,
"");
134 if (GetStringLength(sName) != GetStringLength(sCleansed) || GetStringLength(sCleansed) == 0) {
135 WriteTimestampedLogEntry(
"WARNING: Invalid table name detected for array with tag <" + tag +
">. Only characters (a-zA-Z0-9), _, @, $ and # are allowed. Using <"+sCleansed+
"> instead.");
145 return "\""+sCleansed+
"\"";
151 return "CREATE TABLE IF NOT EXISTS " +
GetTableName(tag, obj) +
" ( ind INTEGER, value TEXT )";
155 string stmt =
"SELECT name FROM sqlite_master WHERE type = 'table' AND name = @tablename;";
156 sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
157 SqlBindString(sqlQuery,
"@tablename",
GetTableName(tag, obj, TRUE));
158 return SqlStep(sqlQuery);
162 if (obj == OBJECT_INVALID)
166 sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), statement);
177 if (obj == OBJECT_INVALID)
180 string stmt =
"SELECT COUNT(1) FROM " +
GetTableName(tag, obj);
181 sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
182 if ( SqlStep(sqlQuery) ) {
183 return SqlGetInt(sqlQuery, 0);
196 string stmt =
"SELECT value FROM " +
GetTableName(tag, obj) +
" WHERE ind = @ind";
197 sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
198 SqlBindInt(sqlQuery,
"@ind", index);
199 if ( SqlStep(sqlQuery) ) {
200 return SqlGetString(sqlQuery, 0);
211 return StringToFloat(st);
220 return StringToInt(st);
227 return OBJECT_INVALID;
229 return StringToObject(st);
242 string stmt =
"SELECT COUNT(1) FROM "+
GetTableName(tag, obj)+
" WHERE value = @element";
244 sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
245 SqlBindString(sqlQuery,
"@element", element);
248 if ( SqlStep(sqlQuery) ) {
249 pos = SqlGetInt(sqlQuery, 0);
274 void Array_Copy(
string tag,
string otherTag,
object obj=OBJECT_INVALID)
281 void Array_Erase(
string tag,
int index,
object obj=OBJECT_INVALID)
285 if (index >= 0 && index < rows) {
286 string stmt =
"DELETE FROM "+
GetTableName(tag, obj)+
" WHERE ind = @ind";
287 sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
288 SqlBindInt(sqlQuery,
"@ind", index);
291 stmt =
"UPDATE "+
GetTableName(tag, obj)+
" SET ind = ind - 1 WHERE ind > @ind";
292 sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
293 SqlBindInt(sqlQuery,
"@ind", index);
309 stmt =
"SELECT IFNULL(MIN(ind),@invalid_index) FROM "+
GetTableName(tag, obj)+
" WHERE value = @element";
310 sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
313 SqlBindString(sqlQuery,
"@element", element);
314 if ( SqlStep(sqlQuery) ) {
315 return SqlGetInt(sqlQuery, 0);
346 if (index >= 0 && index <= rows) {
350 string stmt =
"INSERT INTO "+
GetTableName(tag, obj)+
" VALUES ( @ind, @element )";
351 sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
352 SqlBindInt(sqlQuery,
"@ind", index);
353 SqlBindString(sqlQuery,
"@element", element);
383 string stmt =
"INSERT INTO "+
GetTableName(tag, obj)+
" VALUES ( @ind, @element )";
384 sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
385 SqlBindInt(sqlQuery,
"@ind", rowCount);
386 SqlBindString(sqlQuery,
"@element", element);
417 ExecuteStatement(
"CREATE TABLE " +table+
"_temp AS SELECT ROW_NUMBER() OVER(ORDER BY RANDOM())-1, value FROM " +table, obj);
419 ExecuteStatement(
"INSERT INTO " +table+
" SELECT * FROM " +table+
"_temp", obj);
435 string direction = GetStringUpperCase(dir);
437 if ( ! (direction ==
"ASC" || direction ==
"DESC") ) {
438 WriteTimestampedLogEntry(
"WARNING: Invalid sort direction <" + direction +
"> supplied. Defaulting to ASC.");
443 string orderBy =
"ORDER BY value " + direction;
446 orderBy =
"ORDER BY CAST(value AS INTEGER)" + direction;
449 orderBy =
"ORDER BY CAST(value AS DECIMAL)" + direction;
452 ExecuteStatement(
"CREATE TABLE " +table+
"_temp AS SELECT ROW_NUMBER() OVER(" + orderBy +
")-1, value FROM " +table, obj);
454 ExecuteStatement(
"INSERT INTO " +table+
" SELECT * FROM " +table+
"_temp", obj);
471 void Array_Set_Str(
string tag,
int index,
string element,
object obj=OBJECT_INVALID)
474 if (index >= 0 && index <= rows) {
475 string stmt =
"UPDATE "+
GetTableName(tag, obj)+
" SET value = @element WHERE ind = @ind";
476 sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
477 SqlBindInt(sqlQuery,
"@ind", index);
478 SqlBindString(sqlQuery,
"@element", element);
483 void Array_Set_Flt(
string tag,
int index,
float element,
object obj=OBJECT_INVALID)
488 void Array_Set_Int(
string tag,
int index,
int element,
object obj=OBJECT_INVALID)
493 void Array_Set_Obj(
string tag,
int index,
object element,
object obj=OBJECT_INVALID)
499 if (title !=
"xxx") {
500 WriteTimestampedLogEntry(
"== " + title +
" ======================================");
502 WriteTimestampedLogEntry(
"Table name = " +
GetTableName(tag, obj));
503 string stmt =
"SELECT ind, value FROM " +
GetTableName(tag, obj);
504 sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
507 while ( SqlStep(sqlQuery) ) {
508 ind = SqlGetInt(sqlQuery, 0);
509 value = SqlGetString(sqlQuery, 1);
510 WriteTimestampedLogEntry(tag +
"[" + IntToString(ind) +
"] = " + value);
void Array_SortDescending(string tag, int type=TYPE_STRING, object obj=OBJECT_INVALID)
Sorts the collection based on descending order.
float Array_At_Flt(string tag, int index, object obj=OBJECT_INVALID)
void Array_Resize(string tag, int size, object obj=OBJECT_INVALID)
Resizes the array. If the array is shrinking, it chops off elements at the ned.
void Array_Debug_Dump(string tag, string title="xxx", object obj=OBJECT_INVALID)
void Array_Set_Flt(string tag, int index, float element, object obj=OBJECT_INVALID)
void Array_Set_Obj(string tag, int index, object element, object obj=OBJECT_INVALID)
void Array_Copy(string tag, string otherTag, object obj=OBJECT_INVALID)
Copies the array of name otherTag over the array of name tag.
int Array_Contains_Flt(string tag, float element, object obj=OBJECT_INVALID)
void Array_Shuffle(string tag, object obj=OBJECT_INVALID)
Reorders the array such each possible permutation of elements has equal probability of appearance.
void ExecuteStatement(string statement, object obj=OBJECT_INVALID)
void Array_Insert_Str(string tag, int index, string element, object obj=OBJECT_INVALID)
void Array_Set_Str(string tag, int index, string element, object obj=OBJECT_INVALID)
object Array_At_Obj(string tag, int index, object obj=OBJECT_INVALID)
void Array_Insert_Flt(string tag, int index, float element, object obj=OBJECT_INVALID)
int GetRowCount(string tag, object obj=OBJECT_INVALID)
int Array_Find_Str(string tag, string element, object obj=OBJECT_INVALID)
int TableExists(string tag, object obj=OBJECT_INVALID)
string GetTableName(string tag, object obj=OBJECT_INVALID, int bare=FALSE)
void Array_Insert_Obj(string tag, int index, object element, object obj=OBJECT_INVALID)
string Array_At_Str(string tag, int index, object obj=OBJECT_INVALID)
void Array_Clear(string tag, object obj=OBJECT_INVALID)
Clears the entire array, such that size==0.
void Array_Insert_Int(string tag, int index, int element, object obj=OBJECT_INVALID)
void Array_PushBack_Flt(string tag, float element, object obj=OBJECT_INVALID)
void Array_PushBack_Str(string tag, string element, object obj=OBJECT_INVALID)
void Array_Set_Int(string tag, int index, int element, object obj=OBJECT_INVALID)
void Array_PushBack_Obj(string tag, object element, object obj=OBJECT_INVALID)
int Array_Contains_Obj(string tag, object element, object obj=OBJECT_INVALID)
string GetTableCreateString(string tag, object obj=OBJECT_INVALID)
void Array_Erase(string tag, int index, object obj=OBJECT_INVALID)
Erases the element at index, and shuffles any elements from index size-1 to index + 1 left.
int Array_Contains_Int(string tag, int element, object obj=OBJECT_INVALID)
int Array_At_Int(string tag, int index, object obj=OBJECT_INVALID)
void CreateArrayTable(string tag, object obj=OBJECT_INVALID)
void Array_Sort(string tag, string dir="ASC", int type=TYPE_STRING, object obj=OBJECT_INVALID)
int Array_Find_Obj(string tag, object element, object obj=OBJECT_INVALID)
int Array_Find_Flt(string tag, float element, object obj=OBJECT_INVALID)
int Array_Size(string tag, object obj=OBJECT_INVALID)
Returns the size of the array.
int Array_Find_Int(string tag, int element, object obj=OBJECT_INVALID)
void Array_SortAscending(string tag, int type=TYPE_STRING, object obj=OBJECT_INVALID)
Sorts the collection based on descending order.
int Array_Contains_Str(string tag, string element, object obj=OBJECT_INVALID)
void Array_PushBack_Int(string tag, int element, object obj=OBJECT_INVALID)