Ejemplo n.º 1
0
TEST_F(row, can_count_number_of_columns_in_results) {
    sqlite::row row(make_row("SELECT id FROM test;"));
    EXPECT_EQ(1, row.column_count());
    row = make_row("SELECT id, name FROM test;");
    EXPECT_EQ(2, row.column_count());
    row = make_row("SELECT * FROM test;");
    EXPECT_EQ(2, row.column_count());
}
Ejemplo n.º 2
0
t_rowslist	*make_rowslist(int list_size)
{
  int		m_nb;
  t_rowslist	*row;
  t_rowslist	*buff;
  t_rowslist	*first;

  m_nb = 3;
  if ((buff = malloc(sizeof(t_rowslist))) == NULL)
    return (NULL);
  buff->matchs_nb = 1;
  list_size--;
  first = buff;
  while (list_size)
    {
      if (make_row(&row, &buff, m_nb) == -1)
	return (NULL);
      list_size--;
      m_nb += 2;
    }
  row->next = first;
  first->before = row;
  first->cursor = 1;
  return (first);
}
Ejemplo n.º 3
0
      std::vector<Crails::Front::Element> make_rows(const std::vector<CONTENT_TYPE>& content)
      {
        std::vector<Crails::Front::Element> rows;

        for (const auto& entry : content)
          rows.push_back(make_row(entry));
        return rows;
      }
Ejemplo n.º 4
0
static ERL_NIF_TERM
do_multi_step(ErlNifEnv *env, sqlite3 *db, sqlite3_stmt *stmt, const ERL_NIF_TERM arg)
{
    ERL_NIF_TERM status;
    ERL_NIF_TERM rows = enif_make_list_from_array(env, NULL, 0);
    ERL_NIF_TERM *rowBuffer = NULL;
    int rowBufferSize = 0;

    int chunk_size = 0;
    enif_get_int(env, arg, &chunk_size);

    int rc = sqlite3_step(stmt);
    while (rc == SQLITE_ROW && chunk_size-- > 0)
    {
        if (!rowBufferSize)
            rowBufferSize = sqlite3_column_count(stmt);
        if (rowBuffer == NULL)
            rowBuffer = (ERL_NIF_TERM *) enif_alloc(sizeof(ERL_NIF_TERM)*rowBufferSize);

        rows = enif_make_list_cell(env, make_row(env, stmt, rowBuffer, rowBufferSize), rows);

        if (chunk_size > 0)
            rc = sqlite3_step(stmt);
    }

    switch(rc) {
    case SQLITE_ROW:
        status = make_atom(env, "rows");
        break;
    case SQLITE_BUSY:
        status = make_atom(env, "$busy");
        break;
    case SQLITE_DONE:
        /*
        * Automatically reset the statement after a done so
        * column_names will work after the statement is done.
        *
        * Not resetting the statement can lead to vm crashes.
        */
        sqlite3_reset(stmt);
        status = make_atom(env, "$done");
        break;
    default:
        /* We use prepare_v2, so any error code can be returned. */
        return make_sqlite3_error_tuple(env, rc, db);
    }

    enif_free(rowBuffer);
    return enif_make_tuple2(env, status, rows);
}
Ejemplo n.º 5
0
static ERL_NIF_TERM
do_step(ErlNifEnv *env, sqlite3 *db, sqlite3_stmt *stmt)
{
    int rc = sqlite3_step(stmt);

    if(rc == SQLITE_ROW) 
        return make_row(env, stmt);
    if(rc == SQLITE_DONE) 
	    return make_atom(env, "$done");
    if(rc == SQLITE_BUSY)
	    return make_atom(env, "$busy");

    if(rc == SQLITE_ERROR)
        return make_sqlite3_error_tuple(env, rc, db);
    if(rc == SQLITE_MISUSE)
        return make_error_tuple(env, "misuse");

    return make_error_tuple(env, "unexpected_return_value");
}
Ejemplo n.º 6
0
ETERM *
make_rows(my_ulonglong count)
{
  ETERM **rows, *rc;
  unsigned int i;

  rows = (ETERM **)safe_malloc(numrows * sizeof(ETERM *));
  for (i = 0; i < count; i++) {
    ETERM *rt;

    switch (mysql_stmt_fetch(sth)) {
    case 0:
      rt = make_row();
      rows[i] = erl_format("~w", rt);
      erl_free_term(rt);
      break;
    case MYSQL_NO_DATA:
      rt = erl_format("{error, {mysql_error, no_data}}");
      write_msg(rt);
      erl_free_term(rt);
      exit(3);
    case MYSQL_DATA_TRUNCATED:
      rt = erl_format("{error, {mysql_error, data_truncated}}");
      write_msg(rt);
      erl_free_term(rt);
      exit(3);
    default:
      rt = erl_format("{error, {mysql_error, ~i, ~s}}",
                      mysql_stmt_errno(sth), mysql_stmt_error(sth));
      write_msg(rt);
      erl_free_term(rt);
      exit(3);
    }
  }

  rc = erl_mk_list(rows, count);

  for (i = 0; i < count; i++)
    erl_free_term(rows[i]);
  free(rows);

  return rc;
}
Ejemplo n.º 7
0
static ERL_NIF_TERM
do_step(ErlNifEnv *env, sqlite3 *db, sqlite3_stmt *stmt)
{
    int rc = sqlite3_step(stmt);

    if(rc == SQLITE_ROW) 
        return make_row(env, stmt);
    if(rc == SQLITE_BUSY)
        return make_atom(env, "$busy");

    if(rc == SQLITE_DONE) { 
        /* 
         * Automatically reset the statement after a done so 
         * column_names will work after the statement is done.
         *
         * Not resetting the statement can lead to vm crashes.
         */
        sqlite3_reset(stmt);
        return make_atom(env, "$done");
    }

    /* We use prepare_v2, so any error code can be returned. */
    return make_sqlite3_error_tuple(env, rc, db);
}
Ejemplo n.º 8
0
int insert_element2( RowNode_handle *pp_r,int pos_row,int pos_col,int val )
{
  RowNode_handle pRow = *pp_r, pRowFind;
  
  int result;
  
    /* dummy element node pointer to use in insert row calls */
  ElementNode_handle pColumns = 0;
  
    /* if matrix doesnt exist */
  if(!pRow && val != 0)
  {
      /* make a row */
    *pp_r = make_row(pos_row);
    
      /* insert an element where desired  */
    result =  insert_element(&(*pp_r)->elements, pos_col, val);
  
      /* remove any rows that have been zero'd out */
    ZeroRowRemover(pp_r);
    
      /* return reuslt of insertion */
    return result;
  }  
  
    /* iterate through the rows */
  while(pRow && pRow->pos != pos_row)
    pRow = pRow->next;
  
    /* insert element in row if found */
  if(pRow && pRow->pos == pos_row)
  {
      /* insert element */
    result = insert_element(&pRow->elements, pos_col, val);
    
      /* remove any rows zero'd out */
    ZeroRowRemover(pp_r);
    
      /* return result of insertion */
    return result;
  }
  else /* if row not found, insert it */
  {
      /* dont create row if val desired in non-existent row is 0 */
    if(val == 0)
      return 0;
    
      /* insert a row into this matrix */
    insert_row(pp_r, pos_row, pColumns);
    
      /* get pointer to row inserted */
    pRowFind = find_row(pp_r, pos_row);
    
      /* insert element in row requested */
    result =  insert_element(&pRowFind->elements, pos_col, val);
    
      /* remove any rows that have been zero'd out */
    ZeroRowRemover(pp_r);
    
      /* return result of insertion */
    return result;
  }
}
Ejemplo n.º 9
0
int insert_row( RowNode_handle *p_r,int pos,ElementNode_handle p_e )
{
    /* two pointers to walk list and one to use inserting a node */
  RowNode_handle pRowCurrent = *p_r, pInsert, pRowPrevious = pRowCurrent;
  
    /* case of creating the matrix */
  if(!*p_r)
  {
      /* allocate row */
    *p_r = make_row(pos);
    
      /* check malloc */
    if(!p_r)
      return 1;
    
      /* add columns if valid */
    if(p_e)
      (*p_r)->elements  = p_e;
    
      /* return successful insert */
    return 0;
  }
  
    /* case of inserting at the front */
  if(pRowCurrent->pos > pos)
  {
      /* allocate node to insert */
    pInsert = make_row(pos);
    
      /* check malloc */
    if(!pInsert)
      return 1;
    
      /* add columns if valid */
    if(p_e)
      pInsert->elements = p_e;
    
      /* assign next to previous head row */
    pInsert->next = *p_r;
    
      /* move head pointer */
    *p_r = pInsert;
    
      /* return successful insert */
    return 0;
  }
  
    /* iterate through the rows*/
  while(pRowCurrent && pRowCurrent->pos <= pos)
  {
      /* if row already occupied return 2 */
    if(pRowCurrent->pos == pos)
      return 2;
    
      /* move pointers */
    pRowPrevious = pRowCurrent;
    pRowCurrent = pRowCurrent->next;
  }
  
  /* at this pointer need to insert between previous and current
   * pointers */
  
  
    /* allocate row */
  pInsert = make_row(pos);
  
    /* check malloc */
  if(!pInsert)
    return 1;
    
    /* add columns if valid */
  if(p_e)
    pInsert->elements = p_e;
  
    /* link up the new node */
  pInsert->next = pRowCurrent;
  pRowPrevious->next = pInsert;
  
    /* return successful insert */
  return 0;
}
Ejemplo n.º 10
0
Archivo: main.c Proyecto: musl/DataFace
/*:
 * Handle window loading.
 */
static void load_cb(Window *window) {

	// Right Margin
	static int m = 4;
	// Font Size
	static int s = 31;
	// First Row Offset
	static int o = 0;
	// Row Top Padding
	static int p = 2;

	// Screen Size
	static int w = 144;
	static int h = 168;

	// Load resources we'll have to destroy later.
	s_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TARGA_MS_31));

	// NO DESCENDERS FOR YOU
#define make_row(x) text_layer_create(GRect(m, (x - 1) * (s + p) + o, w, s))

	// Window Background
	//
	s_bg_layer = bitmap_layer_create(GRect(0, 0, w, h));
	bitmap_layer_set_background_color(s_bg_layer, GColorBlack);
	layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bg_layer));

	s_cldr_layer = make_row(1);
	text_layer_set_background_color(s_cldr_layer, GColorClear);
	text_layer_set_text_color(s_cldr_layer, theme_tertiary);
	text_layer_set_font(s_cldr_layer, s_font);
	text_layer_set_text_alignment(s_cldr_layer, GTextAlignmentLeft);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_cldr_layer));

	s_date_layer = make_row(2);
	text_layer_set_background_color(s_date_layer, GColorClear);
	text_layer_set_text_color(s_date_layer, theme_secondary);
	text_layer_set_font(s_date_layer, s_font);
	text_layer_set_text_alignment(s_date_layer, GTextAlignmentLeft);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));

	s_time_layer = make_row(3);
	text_layer_set_background_color(s_time_layer, GColorClear);
	text_layer_set_text_color(s_time_layer, theme_primary);
	text_layer_set_font(s_time_layer, s_font);
	text_layer_set_text_alignment(s_time_layer, GTextAlignmentLeft);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));

	s_wthr_layer = make_row(4);
	text_layer_set_background_color(s_wthr_layer, GColorClear);
	text_layer_set_text_color(s_wthr_layer, theme_info);
	text_layer_set_font(s_wthr_layer, s_font);
	text_layer_set_text_alignment(s_wthr_layer, GTextAlignmentLeft);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_wthr_layer));

	s_blth_layer = make_row(5);
	text_layer_set_background_color(s_blth_layer, GColorClear);
	text_layer_set_text_color(s_blth_layer, theme_tertiary);
	text_layer_set_font(s_blth_layer, s_font);
	text_layer_set_text_alignment(s_blth_layer, GTextAlignmentLeft);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_blth_layer));

	s_batt_layer = make_row(5);
	text_layer_set_background_color(s_batt_layer, GColorClear);
	text_layer_set_text_color(s_batt_layer, theme_tertiary);
	text_layer_set_font(s_batt_layer, s_font);
	text_layer_set_text_alignment(s_batt_layer, GTextAlignmentLeft);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_batt_layer));

#undef make_row

}
Ejemplo n.º 11
0
TEST_F(row, throws_error_when_asked_for_non_existing_column_id) {
    sqlite::row row(make_row("SELECT * FROM test;"));
    EXPECT_DEBUG_DEATH(row[5], "");
}
Ejemplo n.º 12
0
TEST_F(row, provides_corresponding_field_when_given_column_index) {
    sqlite::row row(make_row("SELECT * FROM test;"));
    EXPECT_EQ(1, row[0].as<int>());
    EXPECT_EQ("test", row[1].as<std::string>());
}