Esempio n. 1
0
static sword
ora_describe_define(oraCursor * cursor)
{
	long col = 0;
	int i;
	sb2 type;
	sb4 dbsize;

	if (cursor == NULL) {
		return -1;
	}

	if (cursor->columns) {
		for(i = 0; i < cursor->ncols; i++){
			if (cursor->columns[i].buf)
				efree(cursor->columns[i].buf);
		}
		efree(cursor->columns);
	} 

	cursor->ncols = 0;

	while(1){
		if (odescr(&cursor->cda, (sword) cursor->ncols + 1, &dbsize, (sb2 *)0, (sb1 *)0, 
			   (sb4 *)0, (sb4 *)0,	(sb2 *)0, (sb2 *)0, (sb2 *)0)){
			if (cursor->cda.rc == VAR_NOT_IN_LIST) {
				break;
			} else {
				php3_error(E_WARNING, "%s", ora_error(&cursor->cda));
				cursor->ncols = 0;
				return -1;
			}
		}
		cursor->ncols++;
	}

	if (cursor->ncols > 0){
		cursor->columns = (oraColumn *) emalloc(sizeof(oraColumn) * cursor->ncols);
		if (cursor->columns == NULL){
			php3_error(E_WARNING, "Out of memory");
			return -1;
		}
	}

	for(col = 0; col < cursor->ncols; col++){
		memset(&cursor->columns[col], 0, sizeof(oraColumn));
		cursor->columns[col].cbufl = ORANAMELEN;
		
		if (odescr(&cursor->cda, (sword)col + 1, &cursor->columns[col].dbsize,
				   &cursor->columns[col].dbtype, &cursor->columns[col].cbuf[0],
				   &cursor->columns[col].cbufl, &cursor->columns[col].dsize,
				   &cursor->columns[col].prec, &cursor->columns[col].scale,
				   &cursor->columns[col].nullok)) {
			if (cursor->cda.rc == VAR_NOT_IN_LIST) {
				break;
			} else {
				php3_error(E_WARNING, "%s", ora_error(&cursor->cda));
				return -1;
			}
		}

		cursor->columns[col].cbuf[cursor->columns[col].cbufl] = '\0';

		switch (cursor->columns[col].dbtype) {
			case SQLT_LBI:
				cursor->columns[col].dsize = DB_SIZE;
				type = SQLT_LBI;
				break;
			case SQLT_LNG: 
				cursor->columns[col].dsize = DB_SIZE;
			default:
				type = SQLT_STR;
				break;
		}
		
		if ((cursor->columns[col].buf = (ub1 *) emalloc(cursor->columns[col].dsize + 1)) == NULL){
			php3_error(E_WARNING, "Out of memory");
			return -1;
		}
		/* Define an output variable for the column */
		if (odefin(&cursor->cda, (sword)col + 1, cursor->columns[col].buf, 
				   cursor->columns[col].dsize + 1, type, -1, &cursor->columns[col].indp,
				   (text *) 0, -1, -1, &cursor->columns[col].col_retlen, 
				   &cursor->columns[col].col_retcode)) {
			php3_error(E_WARNING, "%s", ora_error(&cursor->cda));
			return -1;
		}
	}
	return 1;
}
Esempio n. 2
0
File: oracle.c Progetto: akissa/exim
static sword
describe_define(Cda_Def *cda, Ora_Define *def, Ora_Describe *desc)
{
sword col, deflen, deftyp;
static ub1 *defptr;
static sword numwidth = 8;

/* Describe the select-list items. */

for (col = 0; col < MAX_SELECT_LIST_SIZE; col++)
  {
  desc[col].buflen = MAX_ITEM_BUFFER_SIZE;

  if (odescr(cda, col + 1, &desc[col].dbsize,
             &desc[col].dbtype, &desc[col].buf[0],
             &desc[col].buflen, &desc[col].dsize,
             &desc[col].precision, &desc[col].scale,
             &desc[col].nullok) != 0)
    {
    /* Break on end of select list. */
    if (cda->rc == VAR_NOT_IN_LIST) break; else return -1;
    }

  /* Adjust sizes and types for display, handling NUMBER with scale as float. */

  if (desc[col].dbtype == NUMBER_TYPE)
    {
    desc[col].dbsize = numwidth;
    if (desc[col].scale != 0)
      {
      defptr = (ub1 *)&def[col].flt_buf;
      deflen = (sword) sizeof(float);
      deftyp = FLOAT_TYPE;
      desc[col].dbtype = FLOAT_TYPE;
      }
    else
      {
      defptr = (ub1 *)&def[col].int_buf;
      deflen = (sword) sizeof(sword);
      deftyp = INT_TYPE;
      desc[col].dbtype = INT_TYPE;
      }
    }
  else
    {
    if (desc[col].dbtype == DATE_TYPE)
        desc[col].dbsize = 9;
    if (desc[col].dbtype == ROWID_TYPE)
        desc[col].dbsize = 18;
    defptr = def[col].buf;
    deflen = desc[col].dbsize > MAX_ITEM_BUFFER_SIZE ?
      MAX_ITEM_BUFFER_SIZE : desc[col].dbsize + 1;
    deftyp = STRING_TYPE;
    desc[col].dbtype = STRING_TYPE;
    }

  /* Define an output variable */

  if (odefin(cda, col + 1,
             defptr, deflen, deftyp,
             -1, &def[col].indp, (text *) 0, -1, -1,
             &def[col].col_retlen,
             &def[col].col_retcode) != 0)
    return -1;
  }  /* Loop for each column */

return col;
}
Esempio n. 3
0
/*getFieldsInformation - get column names, types, and info
Output: False on error*/
Bool DBCursor_ORACLE::getFieldsInformation()
{
	sb4 dbsize;
	int totalsize = 0;
	fieldCount = 0;
	while (True)
	{
		if (odescr(ORACLE_res, fieldCount + 1, &dbsize, 0, 0, 0, 0, 0, 0, 0))
			if (ORACLE_res->rc == VAR_NOT_IN_LIST)
				break;

			fieldCount++;
	}    
	fields = new DBField *[fieldCount];
	unsigned int i=0;
	for (i=0; i< fieldCount; i++)
	{
		DBField_ORACLE *ofield = new DBField_ORACLE();
		fields[i] = (DBField *)ofield;
		sb4 buflen = F_NAMESIZE;
		sb2 scale, nullok, dbtype;

		odescr(ORACLE_res, i+1, &dbsize, &dbtype, (sb1 *)ofield->fieldName, &buflen, 0, 0, &scale, &nullok);
		ofield->fieldName[buflen] = '\0';
		
		ofield->fieldNum = i + 1;
		
		ofield->maxlength = dbsize+1;
		
		ofield->externaltype = STRING_TYPE;
		switch (dbtype)
		{
		case CHAR_TYPE:
		case VARCHAR2_TYPE:
			ofield->fieldType = FT_CHAR;
			break;
		case NUMBER_TYPE:
			if (scale != 0)
				ofield->fieldType = FT_FLOAT;
			else
				ofield->fieldType = FT_INTEGER;
			break;
		case LONG_TYPE:
			ofield->fieldType = FT_STRING;
			ofield->externaltype = LRAW_TYPE;
			ofield->maxlength = LONG_CHUNK_SIZE;
			break;
		case ROWID_TYPE:
			ofield->fieldType = FT_STRING;
			break;
		case DATE_TYPE :
			ofield->fieldType = FT_DATE;
			break;
		case RAW_TYPE :
		case LRAW_TYPE:
			ofield->fieldType = FT_BLOB;
			ofield->externaltype = LRAW_TYPE;
			ofield->maxlength = LONG_CHUNK_SIZE;
			break;
		default:
			ofield -> fieldType = FT_STRING;
		} 
		
		ofield->isAutoIncrement = False;
		ofield->isPrimaryKey = False;
		ofield->isUnique = False;
		ofield->isNotNull = nullok == 0;
		//allocate for data and bind 
		ofield->maxlength = align(ofield->maxlength); 
		totalsize += ofield->maxlength;
		ofield->freeBuffer = False;
	}
	if (cacherows)
	{
		maxrows = MAXCOLBUF / totalsize;
		if (maxrows > MAXROWNUM) 
			maxrows = MAXROWNUM;
	}
	else
		maxrows = 1;

	for (i = 0; i < fieldCount; i++)
	{
		DBField_ORACLE *ofield = (DBField_ORACLE *)fields[i];
		ofield -> databuffer = new char[maxrows * ofield -> maxlength];
		ofield -> indp = new ub2[maxrows];
		ofield -> dsize = new ub2[maxrows];
		ofield -> errorcode = new ub2[maxrows];
		if (odefin(ORACLE_res, i + 1, (ub1 *)ofield -> databuffer, ofield -> maxlength, ofield -> externaltype, -1, (sb2 *)ofield -> indp, 0, -1, -1, (ub2 *)ofield -> dsize, (ub2 *)ofield -> errorcode))
			return False;
	}
	return True;
}