コード例 #1
0
ファイル: result.c プロジェクト: c42/downpour
static VALUE to_rb_value(char *str, drizzle_column_st *column)
{
  if(str == NULL)
    return Qnil;

#define not_implemented rb_str_new2(str)

  switch(drizzle_column_type(column)) {
    case DRIZZLE_COLUMN_TYPE_DECIMAL:
      return not_implemented;

    case DRIZZLE_COLUMN_TYPE_TINY:
    case DRIZZLE_COLUMN_TYPE_SHORT:
    case DRIZZLE_COLUMN_TYPE_LONG:
      return rb_cstr2inum(str, 10);

    case DRIZZLE_COLUMN_TYPE_FLOAT:
    case DRIZZLE_COLUMN_TYPE_DOUBLE:
      return rb_float_new(strtod(str, NULL));

    case DRIZZLE_COLUMN_TYPE_NULL:
    case DRIZZLE_COLUMN_TYPE_TIMESTAMP:
      return not_implemented;

    case DRIZZLE_COLUMN_TYPE_LONGLONG:
      return rb_cstr2inum(str, 10);

    case DRIZZLE_COLUMN_TYPE_INT24:
    case DRIZZLE_COLUMN_TYPE_DATE:
    case DRIZZLE_COLUMN_TYPE_TIME:
    case DRIZZLE_COLUMN_TYPE_DATETIME:
    case DRIZZLE_COLUMN_TYPE_YEAR:
    case DRIZZLE_COLUMN_TYPE_NEWDATE:
      return not_implemented;

    case DRIZZLE_COLUMN_TYPE_VARCHAR:
      return rb_str_new2(str);

    case DRIZZLE_COLUMN_TYPE_BIT:
    case DRIZZLE_COLUMN_TYPE_NEWDECIMAL:
    case DRIZZLE_COLUMN_TYPE_ENUM:
    case DRIZZLE_COLUMN_TYPE_SET:
    case DRIZZLE_COLUMN_TYPE_TINY_BLOB:
    case DRIZZLE_COLUMN_TYPE_MEDIUM_BLOB:
    case DRIZZLE_COLUMN_TYPE_LONG_BLOB:
    case DRIZZLE_COLUMN_TYPE_BLOB:
    case DRIZZLE_COLUMN_TYPE_VAR_STRING:
    case DRIZZLE_COLUMN_TYPE_STRING:
    case DRIZZLE_COLUMN_TYPE_GEOMETRY:

    default:
      return not_implemented;
  }
}
コード例 #2
0
ファイル: result.c プロジェクト: garsue/pydrizzle
static PyObject*
get_column_desc(int i, drizzle_column_type_t *types, drizzle_column_st *column)
{

    PyObject *o = NULL;

    const char *name;
    drizzle_column_type_t type;
    drizzle_column_flags_t flags;
    drizzle_charset_t charset;
    uint32_t size;
    uint8_t decimals = 0, null_ok = 0;
    size_t max_size;

    name = drizzle_column_name(column);
    DEBUG("name:%s", name);

    type = drizzle_column_type(column);
    DEBUG("type:%u", type);

    size = drizzle_column_size(column);
    DEBUG("size:%u", size);
    
    max_size = drizzle_column_size(column);
    DEBUG("max_size:%" PRIu64, max_size);

    charset = drizzle_column_charset(column);
    DEBUG("charset:%u", charset);

    decimals = drizzle_column_decimals(column);
    DEBUG("decimals:%d", decimals);
    
    flags = drizzle_column_flags(column);
    DEBUG("flags:%d", flags);

    if (flags & DRIZZLE_COLUMN_FLAGS_NOT_NULL) {
        null_ok = 0;
    } else {
        null_ok = 1;
    }
    
    types[i] = type;
    o = Py_BuildValue("(siiiiii)",
            name, type, 0, size, size, decimals, null_ok);
    return o;
}
コード例 #3
0
ngx_int_t
ngx_http_drizzle_output_col(ngx_http_request_t *r, drizzle_column_st *col)
{
    u_char                              *pos, *last;
    ngx_http_upstream_t                 *u = r->upstream;
    drizzle_column_type_t                col_type = 0;
    uint16_t                             std_col_type = 0;
    const char                          *col_name = NULL;
    uint16_t                             col_name_len = 0;
    size_t                               size;

    ngx_http_upstream_drizzle_peer_data_t   *dp = u->peer.data;

    if (col == NULL) {
        return NGX_ERROR;
    }

    col_type = drizzle_column_type(col);
    col_name = drizzle_column_name(col);
    col_name_len = (uint16_t) strlen(col_name);

    size = sizeof(uint16_t)     /* std col type */
         + sizeof(uint16_t)     /* driver-specific col type */
         + sizeof(uint16_t)     /* col name str len */
         + col_name_len         /* col name str len */
         ;

    pos = ngx_http_drizzle_request_mem(r, dp, size);
    if (pos == NULL) {
        return NGX_ERROR;
    }

    last = pos;

    /* std column type */

    std_col_type = (uint16_t) ngx_http_drizzle_std_col_type(col_type);

#if 0
    dd("std col type for %s: %d, %d (%d, %d, %d)",
            col_name, std_col_type, rds_col_type_blob,
            rds_rough_col_type_str,
            rds_rough_col_type_str << 14,
            (uint16_t) (19 | (rds_rough_col_type_str << 14))
            );
#endif

    *(uint16_t *) last = std_col_type;
    last += sizeof(uint16_t);

    /* drizzle column type */
    *(uint16_t *) last = col_type;
    last += sizeof(uint16_t);

    /* column name string length */
    *(uint16_t *) last = col_name_len;
    last += sizeof(uint16_t);

    /* column name string data */
    last = ngx_copy(last, col_name, col_name_len);

    if ((size_t) (last - pos) != size) {
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
               "drizzle: FATAL: output column buffer error");
        return NGX_ERROR;
    }

    return ngx_http_drizzle_submit_mem(r, dp, size, 0 /* last_buf */);
}