Пример #1
0
int DBConnect(lua_State* state)
{
	LUA->CheckType(1, DATABASE_ID);

	Database * mysqldb = *reinterpret_cast<Database **>(LUA->GetUserdata(1));

	if (!mysqldb) {
		LUA->ThrowError("Attempted to call Connect on a shutdown database");
		return 0;
	}

	if (mysqldb->IsConnected()) {
		LUA->ThrowError("Attempted to call Connect on an already connected database");
		return 0;
	}

	std::string error;
	bool success = mysqldb->Initialize(error);

	LUA->PushBool(success);

	if (!success)
	{
		LUA->PushString(error.c_str());
		delete mysqldb;
		return 2;
	}
	return 1;
}
Пример #2
0
int DBEscape(lua_State* state)
{
	LUA->CheckType(1, DATABASE_ID);

	Database * mysqldb = *reinterpret_cast<Database **>(LUA->GetUserdata(1));

	if (!mysqldb) {
		LUA->ThrowError("Attempted to call Escape on a shutdown database");
		return 0;
	}

	if (!mysqldb->IsConnected()) {
		LUA->ThrowError("Attempted to call Escape on a disconnected database");
		return 0;
	}

	LUA->CheckType(2, Type::STRING);

	unsigned int len;
	const char* query = LUA->GetString(2, &len);

	char* escaped = mysqldb->Escape(query, len);
	LUA->PushString(escaped);

	delete[] escaped;
	return 1;
}
Пример #3
0
int DBIsConnected(lua_State* state)
{
	LUA->CheckType(1, DATABASE_ID);

	Database * mysqldb = *reinterpret_cast<Database **>(LUA->GetUserdata(1));

	if (!mysqldb) {
		LUA->ThrowError("Attempted to call IsConnected on a shutdown database");
		return 0;
	}

	LUA->PushBool(mysqldb->IsConnected());
	return 1;
}
Пример #4
0
int DBGetServerVersion(lua_State* state)
{
	LUA->CheckType(1, DATABASE_ID);

	Database * mysqldb = *reinterpret_cast<Database **>(LUA->GetUserdata(1));

	if (!mysqldb) {
		LUA->ThrowError("Attempted to call GetServerVersion on a shutdown database");
		return 0;
	}

	if (!mysqldb->IsConnected()) {
		LUA->ThrowError("Attempted to call GetServerVersion on a disconnected database");
		return 0;
	}

	LUA->PushNumber(mysqldb->GetServerVersion());
	return 1;
}
Пример #5
0
int main()
{

    ServerSocket sSocket(15780);
    printf("   Server Online....!! \n");
    if(db.IsConnected())
    {
        while(true)
        {
            SOCKET s = sSocket.Accept();
            printf("Accepted connection...\n");
            CreateThread(0, 0, (LPTHREAD_START_ROUTINE)GameSocket::ReceiveThread, &s, 0, 0);
        }
    }
    else
    {
        printf("Connection with database failed.\n");
        return 1;
    }
    return 0;
}
Пример #6
0
int DBSetCharacterSet(lua_State* state)
{
	LUA->CheckType(1, DATABASE_ID);

	Database * mysqldb = *reinterpret_cast<Database **>(LUA->GetUserdata(1));

	if (!mysqldb) {
		LUA->ThrowError("Attempted to call SetCharacterSet on a shutdown database");
		return 0;
	}

	if (!mysqldb->IsConnected()) {
		LUA->ThrowError("Attempted to call SetCharacterSet on a disconnected database");
		return 0;
	}

	const char* set = LUA->CheckString(2);

	std::string error;
	LUA->PushBool(mysqldb->SetCharacterSet(set, error));
	LUA->PushString(error.c_str());
	return 2;
}
Пример #7
0
int DBQuery(lua_State* state)
{
	LUA->CheckType(1, DATABASE_ID);

	Database * mysqldb = *reinterpret_cast<Database **>(LUA->GetUserdata(1));

	if (!mysqldb) {
		LUA->ThrowError("Attempted to call Query on a shutdown database");
		return 0;
	}

	if (!mysqldb->IsConnected()) {
		LUA->ThrowError("Attempted to call Query on a disconnected database");
		return 0;
	}

	const char* query = LUA->CheckString(2);

	int callbackfunc = -1;
	if (LUA->GetType(3) == Type::FUNCTION)
	{
		LUA->Push(3);
		callbackfunc = LUA->ReferenceCreate();
	}

	int callbackref = -1;
	int callbackobj = LUA->GetType(4);
	if (callbackobj != Type::NIL)
	{
		LUA->Push(4);
		callbackref = LUA->ReferenceCreate();
	}

	mysqldb->QueueQuery(query, callbackfunc, callbackref, LUA->GetBool(5));
	return 0;
}