コード例 #1
0
caddr_t
box_narrow_string_as_wide (unsigned char *str, caddr_t wide, long max_len, wcharset_t *charset, caddr_t * err_ret, int isbox)
{
  long i, len = (long)(isbox ? (box_length ((box_t) str) - 1) : strlen((const char *) str));
  wchar_t *box;
  size_t wide_len;
  if (!charset)
    {
      client_connection_t *cli = GET_IMMEDIATE_CLIENT_OR_NULL;
      if (cli)
	charset = cli->cli_charset;
    }
  if (!charset)
    charset = default_charset;


  if (max_len > 0 && len > max_len)
    len = max_len;
/*  if (len == 0)
    return NULL; - explicit bug */
  wide_len = (len + 1) * sizeof(wchar_t);
  if (wide_len > MAX_READ_STRING)
    {
      if (err_ret)
	*err_ret = srv_make_new_error ("22023", "SR578", "The expected result length of wide string is too large");
      return NULL;
    }
  box = (wchar_t *) (wide ? wide : dk_alloc_box_zero (wide_len, DV_WIDE));
  for (i = 0; i < len; i++)
    box[i] = CHAR_TO_WCHAR(str[i], charset);
  box[len] = L'\0';
  return ((caddr_t) box);
}
コード例 #2
0
caddr_t
bif_merge_nasa_tjd_to_datetime (caddr_t * qst, caddr_t * err_ret, state_slot_t ** args)
{
  boxint num = bif_long_arg (qst, args, 0, "merge_nasa_tjd_to_datetime");
  caddr_t res = dk_alloc_box_zero (DT_LENGTH, DV_DATETIME);
  DT_SET_DAY (res, num + NASA_TJD_OFFSET);
  if (1 < BOX_ELEMENTS (args))
    {
      double frac = bif_double_arg (qst, args, 1, "merge_nasa_tjd_to_datetime");
      boxint frac_microsec = frac * (60*60*24*1000000.0);
      if ((0 > frac_microsec) || (60*60*24*(boxint)(1000000) <= frac_microsec))
        sqlr_new_error ("22023", "SR644", "Fraction of julian day should be nonnegative and less than 1");
      DT_SET_FRACTION (res, (frac_microsec % 1000000) * 1000);
      frac_microsec = frac_microsec / 1000000;
      DT_SET_SECOND (res, (frac_microsec % 60));
      frac_microsec = frac_microsec / 60;
      DT_SET_MINUTE (res, (frac_microsec % 60));
      frac_microsec = frac_microsec / 60;
      DT_SET_HOUR (res, frac_microsec);
      DT_SET_DT_TYPE (res, DT_TYPE_DATETIME);
    }
  else
    DT_SET_DT_TYPE (res, DT_TYPE_DATE);
  return res;
}
コード例 #3
0
ファイル: CLIcr.c プロジェクト: jplu/virtuoso-opensource
caddr_t *
set_pos_param_row (cli_stmt_t * stmt, int nth)
{
    int btype = stmt->stmt_bind_type;
    int n_cols = BOX_ELEMENTS (stmt->stmt_compilation->sc_columns);
    int iparam = 0;
    caddr_t *row = (caddr_t *) dk_alloc_box_zero (n_cols * sizeof (caddr_t),
                   DV_ARRAY_OF_POINTER);
    col_binding_t *cb = stmt->stmt_cols;

    for (iparam = 0; iparam < n_cols; iparam++)
    {
        if (cb && cb->cb_place)
        {
            int c_type = cb->cb_c_type;
            char *place = cb->cb_place;
            SQLLEN *length = cb->cb_length;
            int rebind_offset = stmt->stmt_imp_row_descriptor ?
                                (stmt->stmt_imp_row_descriptor->d_bind_offset_ptr ? *(stmt->stmt_imp_row_descriptor->d_bind_offset_ptr) : 0) : 0;

            place += btype == 0 ? nth * sqlc_sizeof (c_type, cb->cb_max_length) : nth * btype;
            place += rebind_offset;
            if (length)
            {
                *((char **) &length) += btype == 0 ? nth * sizeof (SDWORD) : btype * nth;
                *((char **) &length) += rebind_offset;
            }
            if (length && SQL_IGNORE == *length)
                row[iparam] = (dk_alloc_box (0, DV_IGNORE));
            else
            {
                caddr_t v = buffer_to_dv (place, length, c_type, c_type, BHID (nth, iparam + 1), NULL, CON_IS_INPROCESS (stmt->stmt_connection));
                row[iparam] = v;

                if (IS_BOX_POINTER (v) && DV_DAE == box_tag (v))
                    dk_set_push (&stmt->stmt_dae, &row[iparam]);
            }
            /* never a BLOB handle, since c_type never == SQL_ONGxx */
        }
        else
            row[iparam] = dk_alloc_box (0, DV_IGNORE);

        if (cb)
            cb = cb->cb_next;
    }

    return row;
}
コード例 #4
0
void
set_xj_pk (xv_join_elt_t * xj) /*get primary key*/
{
  if (xj->xj_table)
    {
      dbe_table_t *tb = sch_name_to_table (wi_inst.wi_schema, xj->xj_table);
      if (!tb)
	{
	    sqlr_error ("S0002", "No table '%.300s' in create xml", xj->xj_table);
	}
      if (!xj->xj_pk)
	{
	  int fill = 0;
	  dbe_key_t *pk = tb->tb_primary_key;
	  xj->xj_pk = (caddr_t *) dk_alloc_box_zero (pk->key_n_significant * sizeof (caddr_t),
	      DV_ARRAY_OF_POINTER);
	  DO_SET (dbe_column_t *, col, &pk->key_parts)
	    {
	      xj->xj_pk[fill++] = box_dv_short_string (col->col_name);
	      if (fill >= pk->key_n_significant)
	        break;
	    }
	  END_DO_SET ();
	}
コード例 #5
0
void
setp_distinct_hash (sql_comp_t * sc, setp_node_t * setp, long n_rows)
{
  int quietcast = sc->sc_cc->cc_query->qr_no_cast_error;
/* This was:  int quietcast = DFE_DT == sc->sc_so->so_dfe->dfe_type ?
    NULL != sqlo_opt_value (sc->sc_so->so_dfe->_.sub.ot->ot_opts, OPT_SPARQL) : 0;
*/
  int inx;
  int n_keys = dk_set_length (setp->setp_keys);
  int n_deps = dk_set_length (setp->setp_dependent);
  NEW_VARZ (hash_area_t, ha);
  DO_SET (state_slot_t *, ssl, &setp->setp_keys)
    {
      if (!quietcast && IS_BLOB_DTP (ssl->ssl_sqt.sqt_dtp))
	sqlc_new_error (sc->sc_cc, "42000", "SQ186",
	    "Long data types not allowed for distinct, order, "
	    "group or join condition columns (%s)", ssl->ssl_name);
      else if (DV_OBJECT == ssl->ssl_sqt.sqt_dtp)
	sqlc_new_error (sc->sc_cc, "42000", "SQ187",
	    "user defined data types not allowed for distinct, order, "
	    "group or join condition columns (%s)", ssl->ssl_name);
    }
  END_DO_SET();
  ha->ha_row_size = 0;
  ha->ha_key = setp_temp_key (setp, &ha->ha_row_size, quietcast);
  setp->setp_ha = setp->setp_reserve_ha = ha;
  ha->ha_tree = ssl_new_tree (sc->sc_cc, "DISTINCT HASH");
  ha->ha_ref_itc = ssl_new_itc (sc->sc_cc);
  ha->ha_insert_itc = ssl_new_itc (sc->sc_cc);
#ifdef NEW_HASH
  ha->ha_bp_ref_itc = ssl_new_itc (sc->sc_cc);
#endif
  ha->ha_n_keys = n_keys;
  ha->ha_n_deps = n_deps;
  if (n_rows < 0)
    n_rows = 100000; /* count probably overflowed.- Large amount */
  else if (n_rows < 1000)
    n_rows = 1000; /* no less than 1000 if overflows memcache, must be at least this much */
  else if (n_rows > 1000000)
    n_rows = 1000000; /* have a cap on hash size */
  ha->ha_row_count = n_rows;
  ha->ha_key_cols = (dbe_col_loc_t *) dk_alloc_box_zero ((n_deps + n_keys + 1) * sizeof (dbe_col_loc_t), DV_CUSTOM);
  for (inx = 0; inx < n_keys + n_deps; inx++)
    {
      dbe_col_loc_t * cl = key_find_cl (ha->ha_key, inx +1);
      ha->ha_key_cols[inx] = cl[0];
      if ((inx >= n_keys) && (cl->cl_fixed_len <= 0))
	ha->ha_memcache_only = 1;
    }
  ha->ha_slots = (state_slot_t **)
    list_to_array (dk_set_conc (dk_set_copy (setp->setp_keys),
				dk_set_copy (setp->setp_dependent)));
#if 1
  if (ha->ha_memcache_only && setp->setp_gb_ops && setp->setp_gb_ops->data)
    {
      inx = n_keys;
      DO_SET (gb_op_t *, op, &(setp->setp_gb_ops))
	{
	  state_slot_t * ssl = ha->ha_slots[inx];
	  switch (op->go_op)
	{
	  case AMMSC_COUNT:
	  case AMMSC_COUNTSUM:
	  case AMMSC_SUM:
	      case AMMSC_AVG:
	  case AMMSC_MIN:
	  case AMMSC_MAX:
		    {
		      /* check dep part to be numeric type */
		      if (IS_NUM_DTP (ssl->ssl_dtp))
	      ha->ha_memcache_only = 0;
		      else
			{
			  ha->ha_memcache_only = 1;
			  goto check_done;
			}
	      break;
		    }
          default:
	      break;
	}
	  inx++;
	}
      END_DO_SET ();
check_done:;
    }
コード例 #6
0
ファイル: CLIcr.c プロジェクト: jplu/virtuoso-opensource
SQLRETURN SQL_API
virtodbc__SQLSetPos (
    SQLHSTMT		hstmt,
    SQLSETPOSIROW	_irow,
    SQLUSMALLINT	fOption,
    SQLUSMALLINT	fLock)
{
    sql_error_rec_t *err_queue = NULL;
    int irow = (int) _irow;
    STMT (stmt, hstmt);
    int n_rows = (int) (irow != 0 ? 1 : (fOption == SQL_ADD ? stmt->stmt_rowset_size : stmt->stmt_rowset_fill));
    /* insert irow==0 is by rowset sz, others are by rowset fill */
    int inx = 0, rc = 0, firstinx = 0, lastinx = 0;
    int co = irow == 0 ? 0 : irow - 1;
    cli_stmt_t *sps = NULL;
    long op = fOption;
    long row_no = irow;
    caddr_t *params = NULL;
    int all_errors = 1;

    stmt->stmt_pending.p_api = SQL_API_SQLSETPOS;
    stmt->stmt_pending.psp_op = fOption;
    stmt->stmt_pending.psp_irow = irow;
    set_error (&stmt->stmt_error, NULL, NULL, NULL);

    if (stmt->stmt_fetch_mode != FETCH_EXT)
    {
        if (!irow && fOption == SQL_POSITION && fLock == SQL_LOCK_NO_CHANGE)
            return SQL_SUCCESS;	/* this is NOP in fact */

        set_error (&stmt->stmt_error, "S1010", "CL007", "SQLSetPos only allowed after SQLExtendedFetch");

        return SQL_ERROR;
    }

    if (co >= stmt->stmt_rowset_fill && op != SQL_ADD)
    {
        set_error (&stmt->stmt_error, "HY092", "CL008", "SQLSetPos irow out of range");

        return SQL_ERROR;
    }

    if (fOption != SQL_REFRESH)
    {
        stmt->stmt_current_of = co;
        stmt_reset_getdata_status (stmt, stmt->stmt_rowset[co]);
        stmt->stmt_current_row = stmt->stmt_rowset[co];
    }

    if (fOption == SQL_POSITION)
        return SQL_SUCCESS;

    if (stmt->stmt_opts->so_cursor_type == SQL_CURSOR_FORWARD_ONLY)
    {
        set_error (&stmt->stmt_error, "HY109", "CL009", "Only SQL_POSITION SQLSetPos option supported for forward cursors");

        return SQL_ERROR;
    }

    if (!stmt->stmt_set_pos_stmt)
    {
        virtodbc__SQLAllocStmt ((SQLHDBC) stmt->stmt_connection, (SQLHSTMT *) & stmt->stmt_set_pos_stmt);
        virtodbc__SQLPrepare ((SQLHSTMT) stmt->stmt_set_pos_stmt, (SQLCHAR *) "__set_pos (?, ?, ?, ?)", SQL_NTS);
    }

    sps = stmt->stmt_set_pos_stmt;

    if (fOption == SQL_POSITION)
    {
        stmt->stmt_current_of = irow;

        return SQL_SUCCESS;
    }

    if (SQL_UPDATE == fOption || SQL_ADD == fOption)
    {
        params = stmt->stmt_param_array;

        if (!params)
        {
            if (0 == irow)
            {
                params = (caddr_t *) dk_alloc_box_zero (n_rows * sizeof (caddr_t), DV_ARRAY_OF_POINTER);
                for (inx = 0; inx < n_rows; inx++)
                {
                    if (NULL == (params[inx] = (caddr_t) set_pos_param_row (stmt, inx)))
                    {
                        dk_free_tree ((box_t) params);
                        return SQL_ERROR;
                    }
                }
            }
            else if (NULL == (params = set_pos_param_row (stmt, irow - 1)))
                return SQL_ERROR;

            if (stmt->stmt_dae)
            {
                stmt->stmt_status = STS_LOCAL_DAE;
                stmt->stmt_param_array = params;

                return SQL_NEED_DATA;
            }
        }

        stmt->stmt_param_array = NULL;
    }

    memset (&stmt->stmt_pending, 0, sizeof (pending_call_t));

    virtodbc__SQLSetParam ((SQLHSTMT) sps, 1, SQL_C_CHAR, SQL_VARCHAR, 0, 0, stmt->stmt_id, NULL);
    virtodbc__SQLSetParam ((SQLHSTMT) sps, 2, SQL_C_LONG, SQL_INTEGER, 0, 0, &op, NULL);
    virtodbc__SQLSetParam ((SQLHSTMT) sps, 3, SQL_C_LONG, SQL_INTEGER, 0, 0, &row_no, NULL);
    virtodbc__SQLSetParam ((SQLHSTMT) sps, 4, SQL_C_BOX, SQL_VARCHAR, 0, 0, &params, NULL);

    stmt->stmt_status = STS_SERVER_DAE;
    rc = virtodbc__SQLExecDirect ((SQLHSTMT) sps, NULL, 0);
    dk_free_tree ((caddr_t) params);

    if (SQL_ERROR == rc)
    {
        err_queue_append (&stmt->stmt_error.err_queue, &sps->stmt_error.err_queue);
        return SQL_ERROR;
    }
    if (0 == irow)
    {
        firstinx = 0;
        lastinx = n_rows;
    }
    else
    {
        firstinx = irow - 1;
        lastinx = irow;
    }

    for (inx = firstinx; inx < lastinx; inx++)
    {
        rc = stmt_process_result ((cli_stmt_t *) sps, 1);

        if (SQL_ERROR == rc)
        {
            sql_error_rec_t *err1 = cli_make_error ("01S01", "CL082", "Error in row in SQLSetPos", 0);

            if (stmt->stmt_row_status)
                stmt->stmt_row_status[inx] = SQL_ROW_ERROR;

            err_queue_append (&err_queue, &err1);
            err_queue_append (&err_queue, &sps->stmt_error.err_queue);
        }
        else if (rc == SQL_SUCCESS && sps->stmt_prefetch_row)
        {
            long stat = (long) unbox (((caddr_t *) sps->stmt_prefetch_row)[0]);

            if (stmt->stmt_row_status)
                stmt->stmt_row_status[inx] = qa_to_row_stat (stat);

            stmt_set_columns (stmt, (caddr_t *) sps->stmt_prefetch_row, inx);
            dk_free_tree ((caddr_t) stmt->stmt_rowset[inx]);
            stmt->stmt_rowset[inx] = (caddr_t *) sps->stmt_prefetch_row;
            sps->stmt_prefetch_row = NULL;
            all_errors = 0;
        }
        else
        {
            int stat = SQL_ROW_SUCCESS;

            all_errors = 0;
            switch (op)
            {
            case SQL_UPDATE:
                stat = SQL_ROW_UPDATED;
                break;

            case SQL_DELETE:
                stat = SQL_ROW_DELETED;
                break;

            case SQL_ADD:
                stat = SQL_ROW_ADDED;
                break;
            }

            if (stmt->stmt_row_status)
                stmt->stmt_row_status[inx] = stat;
        }
    }

    if (SQL_REFRESH == fOption)
        stmt->stmt_current_row = stmt->stmt_rowset[co];

    stmt->stmt_rows_affected = sps->stmt_rows_affected;
    rc = stmt_process_result (sps, 1);	/* the ret from the proc call, w/ possible autocommit txn error code */

    if (rc == SQL_ERROR)
        err_queue_append (&err_queue, &sps->stmt_error.err_queue);

    if (rc == SQL_NO_DATA_FOUND)
        rc = SQL_SUCCESS;

    if (SQL_SUCCESS == rc && err_queue)
    {
        if (all_errors)
            rc = SQL_ERROR;
        else
            rc = SQL_SUCCESS_WITH_INFO;
    }

    set_error (&stmt->stmt_error, NULL, NULL, NULL);
    stmt->stmt_error.err_queue = err_queue;
    stmt->stmt_error.err_queue_head = err_queue;

    return (rc);
}