/*****************************************************************************
 * Copyright (c) 2005  Daniel Lerch Hostalot <http://daniellerch.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a 
 * copy of this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the 
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 ****************************************************************************/



#ifndef __RESULTSET_H__
#define __RESULTSET_H__


#ifdef __cplusplus
extern "C" {
#endif


#include <mysql.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/**
 * Tipo de representacion de un ResultSet. Utilizado para la base de 
 * datos MySQL.
 */
typedef struct resultset_t {

   /** Resultset de MySQL */
   MYSQL_RES *resultset; 

   /** Row de MySQL */
   MYSQL_ROW row; 

   /** Indica el numero actual de etiqueta */
   int nfield; 
}
resultset_t;


/**
 *  Constructor del tipo.
 *
 *  @param *res: resultset de la API de MySQL.
 */
resultset_t *resultset_new(MYSQL_RES* res);

/**
 *  Destructor del tipo.
 *
 *  @param *rs: Objeto con el que trabaja.
 */
void resultset_free(resultset_t *rs);

/**
 *  Avanza a la siguiente fila del resultset si exite.
 *
 *  @param  *rs: Objeto con el que trabaja.
 *  @return int: 1 si existe la siguiente linea, 0 en caso contrario.
 */
int resultset_next(resultset_t *rs);

/**
 *  Avanza a la siguiente columna de la fila del resultset actual.
 *
 *  @param *rs: Objeto con el que trabaja.
 *  @return int: 1 si existe la siguiente columna, 0 en caso contrario.
 */
int resultset_next_field(resultset_t *rs);

/**
 *  Obtiene el resultado de la columna actual
 *
 *  @param *rs: Objeto con el que trabaja.
 *  @return char*: valor de la columna actual.
 */
char* resultset_get_field(resultset_t *rs);


/**
 *  Obtiene el resultado de la columna pasada como parametro
 *
 *  @param *rs: Objeto con el que trabaja.
 *  @param *name: nombre del campo a recuperar.
 *  @return char*: valor de la columna actual.
 */
char* resultset_get_field_by_name (resultset_t *rs, char *name);


#ifdef __cplusplus
}
#endif


#endif


