#if defined _dbx_included
  #endinput
#endif
#define _dbx_included

/**** All natives generate native error if you pass invalid handle to it. ****/


/* 
 * Creates database tuple. Actually, it does not make connection to DB, but creates thread from which
 * all queries will be executed.
 */
native Handle:DBX_MakeDbTuple(const driver[], const host[], const user[], const password[], const db[]);

/* 
 * Executes asynchronous query to DB.
 * Handler prototype is:
 * public QueryHandler(bool:success, Handle:query, error[], errnum, data[], size, Float:queryTime)
 */
native DBX_ThreadQuery(Handle:hDbTuple, const handler[], const query[], const data[]="", dataSize=0);

/*
 * Tries to fetch next row from current resultset in the hQuery.
 * Return values are:
 *	  0 - success, fetched next row
 *	 -1 - success, no more rows
 *	 >0 - error (this should never be returned)
 */
native DBX_NextRow(Handle:hQuery);

/*
 * Gets count of rows in current resultset in the hQuery 
 */
native DBX_GetRowsCount(Handle:hQuery);

/*
 * Checks if current resultset of hQuery have more rows.
 */
native bool:DBX_HaveMoreRows(Handle:hQuery);

/*
 * Sets the row read position in current resultset of hQuery.
 */
native DBX_SetRowReadPos(Handle:hQuery, newPos);

/*
 * Gets affected (by UPDATE) count of rows in current resultset in the hQuery 
 */
native DBX_GetAffectedRowsCount(Handle:hQuery);

/*
 * Checks if hQuery have more resultsets.
 */
native bool:DBX_HaveMoreResults(Handle:hQuery);

/*
 * Tries to fetch next resultset in hQuery
 * Return values are:
 *	  0 - success, fetched next row
 *	 -1 - success, no more rows
 *	 >0 - error (this should never be returned)
 */
native DBX_NextResultSet(Handle:hQuery);

/*
 * Returns number of columns of current resultset of hQuery.
 * Generates native error if current resultset does not have rows.
 * You should ensure that current resultset has rows using 
 * construction like that: if (DBX_GetRowsCount(hQuery) > 0)
 */
native DBX_NumColumns(Handle:hQuery);

/*
 * Returns column ID by its name.
 * Generates native error if current resultset have rows.
 * Generates native error if column with provided name does not found.
 */
native DBX_GetColumnIdByName(Handle:hQuery, const columnName[]);

/*
 * Reads column name by its ID.
 * Generates native error if current resultset have rows.
 * Generates native error if column with provided id does not found.
 */
native DBX_GetColumnNameById(Handle:hQuery, columnId, columnName[], bufLen);

/*
 * Reads string value of column by its ID.
 * Generates native error if current resultset have rows.
 * Generates native error if column with provided id does not found.
 * Generates native error if column value is NULL.
 */
native DBX_ReadString(Handle:hQuery, columnId, data[], dataLen);

/*
 * Reads float value of column by its ID.
 * Generates native error if current resultset have rows.
 * Generates native error if column with provided id does not found.
 * Generates native error if column value is NULL.
 */
native Float:DBX_ReadFloat(Handle:hQuery, columnId);

/*
 * Reads integer value of column by its ID.
 * Generates native error if current resultset have rows.
 * Generates native error if column with provided id does not found.
 * Generates native error if column value is NULL.
 */
native DBX_ReadInt(Handle:hQuery, columnId);

/*
 * Reads original query string of the hQuery.
 */
native DBX_GetQueryString(Handle:hQuery, query[], bufSize);

/*
 * Escapes string so it could be safely used in DB.
 */
native DBX_EscapeString(Handle:hTuple, const srcString[], dstString[], dstLen);

/*
 * Performs formatiing and the escapes resulting string.
 */
native DBX_EscapeStringFmt(Handle:hTuple, dstString[], dstLen, const fmt[], any:...);

/*
 * Checks if column has NULL value
 * Generates native error if current resultset have rows.
 * Generates native error if column with provided id does not found.
  */
native bool:DBX_IsNull(Handle:hQuery, columnId);

/*
 * Gets Last insert ID of current resultset of the hQuery
 */
native DBX_GetLastInsertId(Handle:hQuery);
