示例#1
0
int main(int argc, char *argv[])
{
  attachsql_connect_t *con= NULL;
  attachsql_error_st *error= NULL;
  const char *query= "SELECT * FROM t1 WHERE name='fred'";
  attachsql_return_t ret= ATTACHSQL_RETURN_NONE;
  attachsql_query_row_st *row;
  uint16_t columns, current_column;

  con= attachsql_connect_create("localhost", 3306, "test", "test", "testdb", NULL);
  error= attachsql_query(con, strlen(query), query, 0, NULL);

  while ((ret != ATTACHSQL_RETURN_EOF) && (error == NULL))
  {
    ret= attachsql_connect_poll(con, &error);
    if (ret != ATTACHSQL_RETURN_ROW_READY)
    {
      continue;
    }
    row= attachsql_query_row_get(con, &error);
    columns= attachsql_query_column_count(con);
    for (current_column= 0; current_column < columns; current_column++)
    {
      printf("%.*s ", (int)row[current_column].length, row[current_column].data);
    }
    printf("\n");
    attachsql_query_row_next(con);
  }
  if (error != NULL)
  {
    printf("Error occurred: %s", error->msg);
  }
  attachsql_query_close(con);
  attachsql_connect_destroy(con);
}
示例#2
0
int attachsql_drv_fetch_row(db_result_set_t *rs, db_row_t *row)
{
  attachsql_error_t *error= NULL;
  attachsql_return_t aret= ATTACHSQL_RETURN_NONE;

  /* NYI */

  attachsql_connect_t *con = rs->connection->ptr;

  while((aret != ATTACHSQL_RETURN_EOF) && (aret != ATTACHSQL_RETURN_ROW_READY))
  {
    aret= attachsql_connect_poll(con, &error);

    if (error)
    {
      log_text(LOG_ALERT, "libAttachSQL Query Failed: %u:%s", attachsql_error_code(error), attachsql_error_message(error));
      attachsql_error_free(error);
      return 1;
    }
  }
  if (aret == ATTACHSQL_RETURN_EOF)
  {
    return 1;
  }
  row->ptr= attachsql_query_row_get(con, NULL);
  attachsql_query_row_next(con);

  return 0;
}
示例#3
0
int attachsql_drv_fetch(db_result_set_t *rs)
{
  /* NYI */
  attachsql_connect_t *con = rs->connection->ptr;
  size_t tmp_len;
  uint16_t columns, col;
  attachsql_return_t aret= ATTACHSQL_RETURN_NONE;
  attachsql_error_t *error= NULL;

  while((aret != ATTACHSQL_RETURN_EOF) && (aret != ATTACHSQL_RETURN_ROW_READY))
  {
    aret= attachsql_connect_poll(con, &error);

    if (error)
    {
      log_text(LOG_ALERT, "libAttachSQL Query Failed: %u:%s", attachsql_error_code(error), attachsql_error_message(error));
      attachsql_error_free(error);
      return 1;
    }
  }
  if (aret == ATTACHSQL_RETURN_EOF)
  {
    return 1;
  }
  attachsql_statement_row_get(con, NULL);
  columns= attachsql_query_column_count(con);
  for (col= 0; col < columns; col++)
  {
    switch (attachsql_statement_get_column_type(con, col))
    {
      case ATTACHSQL_COLUMN_TYPE_TINY:
      case ATTACHSQL_COLUMN_TYPE_SHORT:
      case ATTACHSQL_COLUMN_TYPE_LONG:
      case ATTACHSQL_COLUMN_TYPE_YEAR:
      case ATTACHSQL_COLUMN_TYPE_INT24:
        attachsql_statement_get_int(con, col, &error);
        break;
      case ATTACHSQL_COLUMN_TYPE_LONGLONG:
        attachsql_statement_get_bigint(con, col, &error);
        break;
      case ATTACHSQL_COLUMN_TYPE_FLOAT:
        attachsql_statement_get_float(con, col, &error);
        break;
      case ATTACHSQL_COLUMN_TYPE_DOUBLE:
        attachsql_statement_get_double(con, col, &error);
        break;
      default:
        attachsql_statement_get_char(con, col, &tmp_len, &error);
        break;
    }
  }
  attachsql_query_row_next(con);

  return 0;
}
示例#4
0
int main(void)
{
  attachsql_connect_t *con= NULL;
  attachsql_error_t *error= NULL;
  const char *query= "SELECT * FROM t1 WHERE name = ? AND age > ?";
  attachsql_return_t ret= ATTACHSQL_RETURN_NONE;
  attachsql_query_row_st *row;
  uint16_t columns, current_column;
  attachsql_query_parameter_st param[2];

  con= attachsql_connect_create("localhost", 3306, "test", "test", "testdb", NULL);
  const char *name= "fred";
  uint32_t age= 30;
  param[0].type= ATTACHSQL_ESCAPE_TYPE_CHAR;
  param[0].data= (char*)name;
  param[0].length= strlen(name);
  param[1].type= ATTACHSQL_ESCAPE_TYPE_INT;
  param[1].data= &age;
  param[1].is_unsigned= true;
  attachsql_query(con, strlen(query), query, 2, param, &error);

  while ((ret != ATTACHSQL_RETURN_EOF) && (error == NULL))
  {
    ret= attachsql_connect_poll(con, &error);
    if (ret != ATTACHSQL_RETURN_ROW_READY)
    {
      continue;
    }
    row= attachsql_query_row_get(con, &error);
    columns= attachsql_query_column_count(con);
    for (current_column= 0; current_column < columns; current_column++)
    {
      printf("%.*s ", (int)row[current_column].length, row[current_column].data);
    }
    printf("\n");
    attachsql_query_row_next(con);
  }
  if (error != NULL)
  {
    printf("Error occurred: %s", attachsql_error_message(error));
    attachsql_error_free(error);
  }
  attachsql_query_close(con);
  attachsql_connect_destroy(con);
}
示例#5
0
PyObject *_attachsql_QueryObject_row_next(_attachsql_QueryObject *self, PyObject *unused)
{
  attachsql_query_row_next(self->pycon->conn);
  Py_RETURN_NONE;
}