Add tests and dbi/handle changes.

This commit is contained in:
David Anderson 2014-06-16 01:50:42 -07:00
parent b9203e2491
commit 5bb4aeba89
17 changed files with 211 additions and 22 deletions

View File

@ -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,

View File

@ -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

View File

@ -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;
}

View File

@ -0,0 +1,10 @@
native CloseHandle(Handle:this[]);
methodmap Handle {
Clone = native Handle:CloneHandle(Handle:this);
Close = CloseHandle;
};
public main()
{
}

View 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;
}

View 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();
}

View File

@ -0,0 +1,11 @@
native CloseHandle(Handle:this);
methodmap Handle {
Clone = native Handle:CloneHandle(Handle:this);
Close = CloseHandle;
};
public main()
{
main.Close();
}

View File

@ -0,0 +1,10 @@
native CloseHandle(HandleEgg:this);
methodmap Handle {
Clone = native Handle:CloneHandle(Handle:this);
Close = CloseHandle;
};
public main()
{
}

View File

@ -0,0 +1,10 @@
native CloseHandle({Handle, Egg}:this);
methodmap Handle {
Clone = native Handle:CloneHandle(Handle:this);
Close = CloseHandle;
};
public main()
{
}

View File

@ -0,0 +1,10 @@
native CloseHandle(this);
methodmap Handle {
Clone = native Handle:CloneHandle(Handle:this);
Close = CloseHandle;
};
public main()
{
}

View File

@ -0,0 +1,10 @@
native CloseHandle(&Handle:this);
methodmap Handle {
Clone = native Handle:CloneHandle(Handle:this);
Close = CloseHandle;
};
public main()
{
}

View 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();
}

View 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();
}

View 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)
}

View 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();
}

View 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)
}

View 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();
}