Exemple #1
0
/*
 * Function: setup
 *
 * Description: This routine does the necessary setup to execute the SQL
 *              statement. Specifically, it does the open, parse, bind and
 *              define phases as needed.
 *
 */
void setup()
{

  colp *colsptr;                                        /* temporary pointer */
  sword colindex;

  if (oopen(&cda, &lda, (text *) 0, -1, -1, (text *) 0, -1))         /* open */
  {
    err_report(&cda);
    do_exit(OCI_EXIT_FAILURE);
  }

  if (oparse(&cda, sqlstmt, (sb4) -1, DEFER_PARSE,                  /* parse */
               (ub4) VERSION_7))
  {
    err_report(&cda);
    do_exit(OCI_EXIT_FAILURE);
  }

                                                          /* bind the scalar */

  if (obndra(&cda, (text *)":numins", -1,
             (ub1 *)&numinsert, (sword)sizeof(numinsert),
             SQLT_INT, -1, (sb2 *) 0, (ub2 *)0, (ub2 *)0,
             (ub4)0, (ub4 *)0, (text *)0, -1, -1))                   /* bind */
  {
    err_report(&cda);
    do_exit(OCI_EXIT_FAILURE);
  }

  if (obndra(&cda, (text *)":retval", -1,
             (ub1 *)&retval, (sword)sizeof(retval),
             SQLT_INT, -1, (sb2 *) 0, (ub2 *)0, (ub2 *)0,
             (ub4)0, (ub4 *)0, (text *)0, -1, -1))                   /* bind */
  {
    err_report(&cda);
    do_exit(OCI_EXIT_FAILURE);
  }

  cols = malloc_col(NUMCOLS);
  colsptr = cols;
  for (colindex = 0; colindex < NUMCOLS; colindex++, colsptr++)
  {

    colsptr->c_size  = coltable[colindex].size;
    colsptr->c_type  = coltable[colindex].type;
    colsptr->c_indp  = (sb2*)malloc((size_t)(MAX_ROWS_PER_INSERT*sizeof(sb2)));
    memset((dvoid *)colsptr->c_indp, 0, MAX_ROWS_PER_INSERT * sizeof(sb2));
    colsptr->c_rlen  = (ub2*)malloc((size_t)(MAX_ROWS_PER_INSERT*sizeof(ub2)));
    memset((dvoid *)colsptr->c_rlen, 0, MAX_ROWS_PER_INSERT * sizeof(ub2));
    colsptr->c_rcode = (ub2*)malloc((size_t)(MAX_ROWS_PER_INSERT*sizeof(ub2)));
    memset((dvoid *)colsptr->c_rcode, 0, MAX_ROWS_PER_INSERT * sizeof(ub2));
    colsptr->c_buf   =
                  (ub1 *)malloc((size_t)(MAX_ROWS_PER_INSERT*colsptr->c_size));
    memset((dvoid *)colsptr->c_buf, 0, MAX_ROWS_PER_INSERT * colsptr->c_size);
    colsptr->c_curlen = 0;

    switch (colindex) {
    case(0) :

/* GOTCHA!!! - need to pass in zeroes for mal and cal parameters when
   running a regular insert. Set it to non-zero when using plsql */
        if (obndra(&cda, (text *)":col1", -1,
                   colsptr->c_buf, colsptr->c_size,
                   (sword)colsptr->c_type, (sword) -1,
                   (sb2 *)colsptr->c_indp, colsptr->c_rlen, colsptr->c_rcode,
                   (ub4)MAX_ROWS_PER_INSERT, (ub4 *)&(colsptr->c_curlen),
                   (text *)0, -1, -1))
        {
          err_report(&cda);
          do_exit(OCI_EXIT_FAILURE);
        }
        break;
    }

  }

}
Exemple #2
0
/* {{{ proto int ora_bind(int cursor, string php_variable_name, string sql_parameter_name, int length [, int type])
   Bind a PHP variable to an Oracle parameter */
void php3_Ora_Bind(INTERNAL_FUNCTION_PARAMETERS)
{ /* cursor_ind, php_var_name, sql_var_name, data_len [, inout]*/
	/* inout: 0 = in/out, 1 = in, 2 = out */
	int argc;
	pval *argv[5];
	oraParam *newparam, *paramptr;
	oraCursor *cursor;
	char *paramname;

	argc = ARG_COUNT(ht);
	if (argc < 4 || argc > 5 || getParametersArray(ht, argc, argv) == FAILURE){
		WRONG_PARAM_COUNT;
	}
	convert_to_long(argv[0]);
	convert_to_string(argv[1]);
	convert_to_string(argv[2]);
	convert_to_long(argv[3]);
		
	cursor = ora_get_cursor(list, argv[0]->value.lval);
	if (cursor == NULL) {
		php3_error(E_WARNING, "Invalid cursor index %d",
				   argv[0]->value.lval);
		RETURN_FALSE;
	}

	if(cursor->params == NULL){
		cursor->params = (HashTable *)emalloc(sizeof(HashTable));
		if (!cursor->params ||
			_php3_hash_init(cursor->params, 19, NULL,
							HASH_DTOR pval_ora_param_destructor, 0) == FAILURE) {
			php3_error(E_ERROR, "Unable to initialize parameter list");
			RETURN_FALSE;
		}
	}
	if((newparam = (oraParam *)emalloc(sizeof(oraParam))) == NULL){
		php3_error(E_WARNING, "Out of memory for parameter");
		RETURN_FALSE;
	}

	if((paramname = estrndup(argv[1]->value.str.val, argv[1]->value.str.len)) == NULL){
		php3_error(E_WARNING, "Out of memory for parametername");
		efree(newparam);
		RETURN_FALSE;
	}

	if (_php3_hash_add(cursor->params, paramname, argv[1]->value.str.len + 1, newparam, sizeof(oraParam), (void **)&paramptr) == FAILURE) {
		/* XXX _php3_hash_destroy */
		efree(paramname);
		efree(newparam);
		php3_error(E_ERROR, "Could not make parameter placeholder");
		RETURN_FALSE;
	}

	efree(newparam);
	efree(paramname);

	paramptr->progvl = argv[3]->value.lval + 1;
	if(argc > 4){
		convert_to_long(argv[4]);
		paramptr->inout = (short)argv[4]->value.lval;
	}else{
		paramptr->inout = 0;
	}

	if((paramptr->progv = (text *)emalloc(paramptr->progvl)) == NULL){		
		php3_error(E_WARNING, "Out of memory for parameter value");
		RETURN_FALSE;
	}

/* XXX Maximum for progvl */
	paramptr->alen = paramptr->progvl;

	if (obndra(&cursor->cda,              
			   argv[2]->value.str.val,
			   -1,
			   (ub1 *)paramptr->progv,
			   paramptr->progvl,
			   SQLT_STR, /* ftype */
			   -1, /* scale */
			   0/*&paramptr->ind*/, /* ind */
			   &paramptr->alen, /* alen */
			   0 /*&paramptr->arcode*/,
			   0, /* maxsize */
			   0,
			   0,
			   -1,
			   -1)) {
		php3_error(E_WARNING, "Ora_Bind failed (%s)",
				   ora_error(&cursor->cda));
		RETURN_FALSE;
	}

	cursor->nparams++;
	RETURN_TRUE;
}