mirror of
https://github.com/alliedmodders/sourcemod.git
synced 2025-12-06 18:08:36 +00:00
Add tests and dbi/handle changes.
This commit is contained in:
parent
b9203e2491
commit
5bb4aeba89
@ -701,18 +701,7 @@ native SQL_TQuery(Handle:database, SQLTCallback:callback, const String:query[],
|
||||
*
|
||||
* @return A transaction handle.
|
||||
*/
|
||||
native Handle:SQL_CreateTransaction();
|
||||
|
||||
/**
|
||||
* Adds a query to a transaction object.
|
||||
*
|
||||
* @param txn A transaction handle.
|
||||
* @param query Query string.
|
||||
* @param data Extra data value to pass to the final callback.
|
||||
* @return The index of the query in the transaction's query list.
|
||||
* @error Invalid transaction handle.
|
||||
*/
|
||||
native SQL_AddQuery(Handle:txn, const String:query[], any:data=0);
|
||||
native Transaction:SQL_CreateTransaction();
|
||||
|
||||
/**
|
||||
* Callback for a successful transaction.
|
||||
@ -739,6 +728,20 @@ functag public SQLTxnSuccess(Handle:db, any:data, numQueries, Handle:results[],
|
||||
*/
|
||||
functag public SQLTxnFailure(Handle:db, any:data, numQueries, const String:error[], failIndex, any:queryData[]);
|
||||
|
||||
methodmap Transaction < Handle
|
||||
{
|
||||
/**
|
||||
* Adds a query to a transaction object.
|
||||
*
|
||||
* @param txn A transaction handle.
|
||||
* @param query Query string.
|
||||
* @param data Extra data value to pass to the final callback.
|
||||
* @return The index of the query in the transaction's query list.
|
||||
* @error Invalid transaction handle.
|
||||
*/
|
||||
AddQuery = native SQL_AddQuery(Transaction:txn, const String:query[], any:data=0);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a transaction to the database thread. The transaction handle is
|
||||
* automatically closed. When the transaction completes, the optional
|
||||
@ -755,7 +758,7 @@ functag public SQLTxnFailure(Handle:db, any:data, numQueries, const String:error
|
||||
*/
|
||||
native SQL_ExecuteTransaction(
|
||||
Handle:db,
|
||||
Handle:txn,
|
||||
Transaction:txn,
|
||||
SQLTxnSuccess:onSuccess=SQLTxnSuccess:-1,
|
||||
SQLTxnFailure:onError=SQLTxnFailure:-1,
|
||||
any:data=0,
|
||||
|
||||
@ -76,6 +76,15 @@ native bool:CloseHandle(Handle:hndl);
|
||||
*/
|
||||
native Handle:CloneHandle(Handle:hndl, Handle:plugin=INVALID_HANDLE);
|
||||
|
||||
/**
|
||||
* Helper for object-oriented syntax.
|
||||
*/
|
||||
methodmap Handle
|
||||
{
|
||||
Clone = CloneHandle;
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
/**
|
||||
* Do not use this function. Returns if a Handle and its contents
|
||||
* are readable, whereas INVALID_HANDLE only checks for the absence
|
||||
|
||||
@ -279,10 +279,10 @@ public Action:Command_TestTxn(args)
|
||||
|
||||
SetTestContext("CreateTransaction");
|
||||
|
||||
new Handle:txn = SQL_CreateTransaction();
|
||||
AssertEq("AddQuery", SQL_AddQuery(txn, "INSERT INTO egg (id) VALUES (4)", 50), 0);
|
||||
AssertEq("AddQuery", SQL_AddQuery(txn, "INSERT INTO egg (id) VALUES (5)", 60), 1);
|
||||
AssertEq("AddQuery", SQL_AddQuery(txn, "SELECT COUNT(id) FROM egg", 70), 2);
|
||||
new Transaction:txn = SQL_CreateTransaction();
|
||||
AssertEq("AddQuery", txn.AddQuery("INSERT INTO egg (id) VALUES (4)", 50), 0);
|
||||
AssertEq("AddQuery", txn.AddQuery("INSERT INTO egg (id) VALUES (5)", 60), 1);
|
||||
AssertEq("AddQuery", txn.AddQuery("SELECT COUNT(id) FROM egg", 70), 2);
|
||||
SQL_ExecuteTransaction(
|
||||
db,
|
||||
txn,
|
||||
@ -292,9 +292,9 @@ public Action:Command_TestTxn(args)
|
||||
);
|
||||
|
||||
txn = SQL_CreateTransaction();
|
||||
AssertEq("AddQuery", SQL_AddQuery(txn, "INSERT INTO egg (id) VALUES (6)", 50), 0);
|
||||
AssertEq("AddQuery", SQL_AddQuery(txn, "INSERT INTO egg (id) VALUES (6)", 60), 1);
|
||||
AssertEq("AddQuery", SQL_AddQuery(txn, "SELECT COUNT(id) FROM egg", 70), 2);
|
||||
AssertEq("AddQuery", txn.AddQuery("INSERT INTO egg (id) VALUES (6)", 50), 0);
|
||||
AssertEq("AddQuery", txn.AddQuery("INSERT INTO egg (id) VALUES (6)", 60), 1);
|
||||
AssertEq("AddQuery", txn.AddQuery("SELECT COUNT(id) FROM egg", 70), 2);
|
||||
SQL_ExecuteTransaction(
|
||||
db,
|
||||
txn,
|
||||
@ -306,13 +306,13 @@ public Action:Command_TestTxn(args)
|
||||
// Make sure the transaction was rolled back - COUNT should be 5.
|
||||
txn = SQL_CreateTransaction();
|
||||
AssertEq("CloneHandle", _:CloneHandle(txn), _:INVALID_HANDLE);
|
||||
SQL_AddQuery(txn, "SELECT COUNT(id) FROM egg");
|
||||
txn.AddQuery("SELECT COUNT(id) FROM egg");
|
||||
SQL_ExecuteTransaction(
|
||||
db,
|
||||
txn,
|
||||
Txn_Test3_OnSuccess
|
||||
);
|
||||
|
||||
CloseHandle(db);
|
||||
db.Close();
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
10
sourcepawn/compiler/tests/fail-array-on-implicit-this.sp
Normal file
10
sourcepawn/compiler/tests/fail-array-on-implicit-this.sp
Normal file
@ -0,0 +1,10 @@
|
||||
native CloseHandle(Handle:this[]);
|
||||
|
||||
methodmap Handle {
|
||||
Clone = native Handle:CloneHandle(Handle:this);
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
public main()
|
||||
{
|
||||
}
|
||||
15
sourcepawn/compiler/tests/fail-bad-upcast.sp
Normal file
15
sourcepawn/compiler/tests/fail-bad-upcast.sp
Normal file
@ -0,0 +1,15 @@
|
||||
native CloseHandle(Handle:this);
|
||||
|
||||
methodmap Handle {
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
methodmap Crab {
|
||||
};
|
||||
|
||||
public main()
|
||||
{
|
||||
new Crab:x;
|
||||
new Handle:y;
|
||||
x = y;
|
||||
}
|
||||
13
sourcepawn/compiler/tests/fail-method-on-array.sp
Normal file
13
sourcepawn/compiler/tests/fail-method-on-array.sp
Normal file
@ -0,0 +1,13 @@
|
||||
native CloseHandle(Handle:this);
|
||||
|
||||
methodmap Handle {
|
||||
Clone = native Handle:CloneHandle(Handle:this);
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
public main()
|
||||
{
|
||||
new Handle:x[2];
|
||||
|
||||
x.Close();
|
||||
}
|
||||
11
sourcepawn/compiler/tests/fail-method-on-function.sp
Normal file
11
sourcepawn/compiler/tests/fail-method-on-function.sp
Normal file
@ -0,0 +1,11 @@
|
||||
native CloseHandle(Handle:this);
|
||||
|
||||
methodmap Handle {
|
||||
Clone = native Handle:CloneHandle(Handle:this);
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
public main()
|
||||
{
|
||||
main.Close();
|
||||
}
|
||||
10
sourcepawn/compiler/tests/fail-mismatch-on-implicit-this.sp
Normal file
10
sourcepawn/compiler/tests/fail-mismatch-on-implicit-this.sp
Normal file
@ -0,0 +1,10 @@
|
||||
native CloseHandle(HandleEgg:this);
|
||||
|
||||
methodmap Handle {
|
||||
Clone = native Handle:CloneHandle(Handle:this);
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
public main()
|
||||
{
|
||||
}
|
||||
10
sourcepawn/compiler/tests/fail-multi-tag-on-implicit-this.sp
Normal file
10
sourcepawn/compiler/tests/fail-multi-tag-on-implicit-this.sp
Normal file
@ -0,0 +1,10 @@
|
||||
native CloseHandle({Handle, Egg}:this);
|
||||
|
||||
methodmap Handle {
|
||||
Clone = native Handle:CloneHandle(Handle:this);
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
public main()
|
||||
{
|
||||
}
|
||||
10
sourcepawn/compiler/tests/fail-no-tag-on-implicit-this.sp
Normal file
10
sourcepawn/compiler/tests/fail-no-tag-on-implicit-this.sp
Normal file
@ -0,0 +1,10 @@
|
||||
native CloseHandle(this);
|
||||
|
||||
methodmap Handle {
|
||||
Clone = native Handle:CloneHandle(Handle:this);
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
public main()
|
||||
{
|
||||
}
|
||||
10
sourcepawn/compiler/tests/fail-ref-on-implicit-this.sp
Normal file
10
sourcepawn/compiler/tests/fail-ref-on-implicit-this.sp
Normal file
@ -0,0 +1,10 @@
|
||||
native CloseHandle(&Handle:this);
|
||||
|
||||
methodmap Handle {
|
||||
Clone = native Handle:CloneHandle(Handle:this);
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
public main()
|
||||
{
|
||||
}
|
||||
15
sourcepawn/compiler/tests/ok-inheritance.sp
Normal file
15
sourcepawn/compiler/tests/ok-inheritance.sp
Normal file
@ -0,0 +1,15 @@
|
||||
native CloseHandle(Handle:this);
|
||||
|
||||
methodmap Handle {
|
||||
Clone = native Handle:CloneHandle(Handle:this);
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
methodmap Crab < Handle {
|
||||
};
|
||||
|
||||
public main()
|
||||
{
|
||||
new Crab:x;
|
||||
x.Close();
|
||||
}
|
||||
15
sourcepawn/compiler/tests/ok-method-on-const.sp
Normal file
15
sourcepawn/compiler/tests/ok-method-on-const.sp
Normal file
@ -0,0 +1,15 @@
|
||||
native CloseHandle(Handle:this);
|
||||
|
||||
enum Handle {
|
||||
INVALID_HANDLE = 0,
|
||||
};
|
||||
|
||||
methodmap Handle {
|
||||
Clone = native Handle:CloneHandle(Handle:this);
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
public main()
|
||||
{
|
||||
INVALID_HANDLE.Close();
|
||||
}
|
||||
17
sourcepawn/compiler/tests/ok-method-on-constref.sp
Normal file
17
sourcepawn/compiler/tests/ok-method-on-constref.sp
Normal file
@ -0,0 +1,17 @@
|
||||
native CloseHandle(Handle:this);
|
||||
|
||||
methodmap Handle {
|
||||
Clone = native Handle:CloneHandle(Handle:this);
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
f(const &Handle:x)
|
||||
{
|
||||
x.Close()
|
||||
}
|
||||
|
||||
public main()
|
||||
{
|
||||
new Handle:x;
|
||||
f(x)
|
||||
}
|
||||
12
sourcepawn/compiler/tests/ok-method-on-element.sp
Normal file
12
sourcepawn/compiler/tests/ok-method-on-element.sp
Normal file
@ -0,0 +1,12 @@
|
||||
native CloseHandle(Handle:this);
|
||||
|
||||
methodmap Handle {
|
||||
Clone = native Handle:CloneHandle(Handle:this);
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
public main()
|
||||
{
|
||||
new Handle:x[2];
|
||||
x[1].Close();
|
||||
}
|
||||
17
sourcepawn/compiler/tests/ok-method-on-ref.sp
Normal file
17
sourcepawn/compiler/tests/ok-method-on-ref.sp
Normal file
@ -0,0 +1,17 @@
|
||||
native CloseHandle(Handle:this);
|
||||
|
||||
methodmap Handle {
|
||||
Clone = native Handle:CloneHandle(Handle:this);
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
f(&Handle:x)
|
||||
{
|
||||
x.Close()
|
||||
}
|
||||
|
||||
public main()
|
||||
{
|
||||
new Handle:x;
|
||||
f(x)
|
||||
}
|
||||
12
sourcepawn/compiler/tests/ok-method-on-scalar.sp
Normal file
12
sourcepawn/compiler/tests/ok-method-on-scalar.sp
Normal file
@ -0,0 +1,12 @@
|
||||
native CloseHandle(Handle:this);
|
||||
|
||||
methodmap Handle {
|
||||
Clone = native Handle:CloneHandle(Handle:this);
|
||||
Close = CloseHandle;
|
||||
};
|
||||
|
||||
public main()
|
||||
{
|
||||
new Handle:x;
|
||||
x.Close();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user