Exemplo n.º 1
0
static cell AMX_NATIVE_CALL SQL_MakeDbTuple(AMX *amx, cell *params)
{
	SQL_Connection *sql = new SQL_Connection;
	int len;

	sql->port = 0;
	sql->host = strdup("");
	sql->user = strdup("");
	sql->pass = strdup("");

	char *db = MF_GetAmxString(amx, params[4], 0, &len);
	char path[255];
	FILE *fp;

	MF_BuildPathnameR(path, sizeof(path)-1, "%s", db);
	if ((fp=fopen(path, "rb")))
	{
		fclose(fp);
		sql->db = strdup(path);
	} else {
		MF_BuildPathnameR(path, sizeof(path)-1, "%s/sqlite3/%s.sq3",
			MF_GetLocalInfo("amxx_datadir", "addons/amxmodx/data"),
			db);
		sql->db = strdup(path);
	}

	unsigned int num = MakeHandle(sql, Handle_Connection, FreeConnection);

	return num;
}
Exemplo n.º 2
0
static cell AMX_NATIVE_CALL SQL_Connect(AMX *amx, cell *params)
{
	SQL_Connection *sql = (SQL_Connection *)GetHandle(params[1], Handle_Connection);
	if (!sql)
	{
		MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
		return 0;
	}

	DatabaseInfo nfo;
	nfo.database = sql->db;
	nfo.user = "";
	nfo.pass = "";
	nfo.port = 0;
	nfo.host = "";

	char buffer[512];
	int errcode;

	IDatabase *pDb = g_Sqlite.Connect(&nfo, &errcode, buffer, sizeof(buffer)-1);

	if (!pDb)
	{
		cell *c_err = MF_GetAmxAddr(amx, params[2]);

		*c_err = errcode;
		MF_SetAmxString(amx, params[3], buffer, params[4]);

		return 0;
	}

	return MakeHandle(pDb, Handle_Database, FreeDatabase);
}
Exemplo n.º 3
0
CacheHandle CacheMgr::NewObject(void *pv, word cb, word wfHints)
{
	// Apply limits if asked

	if (m_cbLimit != 0) {
		while (m_cbTotalSize + cb > m_cbLimit) {
			if (!MakeSpace(m_cbTotalSize + cb - m_cbLimit))
				return NULL;
		}
	}

	// Free up an entry if we need to

	if (m_pceFree == NULL) {
		// No free slots available. Discard the oldest entry for reuse.

		for (CacheEntry *pceT = m_pceFirst->pcePrev; pceT != NULL; pceT = pceT->pcePrev) {
			// If we loop back to m_pceFirst, then all CacheEntries are locked. No way!

			Assert(pceT != m_pceFirst);
			if ((pceT->wUniqueLock & kwLockMask) == 0) {
				Discard(pceT);
				break;
			}
		}
	}
	CacheEntry *pce = m_pceFree->pcePrev;
	Assert(pce != NULL);
	if (pce == NULL)
		return NULL;

	// Alloc the object

	pce->hmem = gmmgr.AllocHandle(cb, wfHints);
	Assert(pce->hmem != NULL);
	if (pce->hmem == NULL)
		return NULL;
	pce->cbSize = cb;

	// Write in data

	if (pv != NULL)
		gmmgr.WriteHandle(pce->hmem, 0, pv, cb);

	// Take off free list, put at start of the alloced list

	RemoveFromFreeList(pce);
	Add(pce);
	m_cbTotalSize += cb;
	return MakeHandle(pce);
}
Exemplo n.º 4
0
//public QueryHandler(state, Handle:query, error[], errnum, data[], size)
void MysqlThread::Execute()
{
	cell data_addr;
	if (m_datalen)
	{
		data_addr = MF_PrepareCellArray(m_data, m_datalen);
	} else {
		static cell tmpdata[1] = {0};
		data_addr = MF_PrepareCellArray(tmpdata, 1);
	}
	int state = 0;
	if (!m_qrInfo.connect_success)
	{
		state = -2;
	} else if (!m_qrInfo.query_success) {
		state = -1;
	}
	float diff = gpGlobals->time - m_qrInfo.queue_time;
	cell c_diff = amx_ftoc(diff);
	unsigned int hndl = MakeHandle(&m_qrInfo.amxinfo, Handle_Query, NullFunc);
	if (state != 0)
	{
		MF_ExecuteForward(m_fwd, 
			(cell)state, 
			(cell)hndl, 
			m_qrInfo.amxinfo.error, 
			m_qrInfo.amxinfo.info.errorcode,
			data_addr,
			m_datalen,
			c_diff);
	} else {
		MF_ExecuteForward(m_fwd,
			(cell)0,
			(cell)hndl,
			"",
			(cell)0,
			data_addr,
			m_datalen,
			c_diff);
	}
		FreeHandle(hndl);
	if (m_qrInfo.amxinfo.pQuery)
	{
		m_qrInfo.amxinfo.pQuery->FreeHandle();
		m_qrInfo.amxinfo.pQuery = NULL;
	}
	delete [] m_qrInfo.amxinfo.opt_ptr;
	m_qrInfo.amxinfo.opt_ptr = NULL;
}
Exemplo n.º 5
0
static cell AMX_NATIVE_CALL SQL_PrepareQuery(AMX *amx, cell *params)
{
	IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database);
	if (!pDb)
	{
		MF_LogError(amx, AMX_ERR_NATIVE, "Invalid database handle: %d", params[1]);
		return 0;
	}

	int len;
	char *fmt = MF_FormatAmxString(amx, params, 2, &len);

	IQuery *pQuery = pDb->PrepareQuery(fmt);
	if (!pQuery)
		return 0;

	AmxQueryInfo *qinfo = new AmxQueryInfo;
	qinfo->pQuery = pQuery;

	memset(&qinfo->info, 0, sizeof(QueryInfo));

	return MakeHandle(qinfo, Handle_Query, FreeQuery);
}