?? oradbutil.pc
字號:
sprintf(tmpField,"%s","NULL");
}
else {
if (select_dp->T[i] == 3)
{
/*sprintf(tmpField,"%*d",(int)select_dp->L[i],*(int *)select_dp->V[
i]);*/
sprintf(tmpNum, "%d",*(int *)select_dp->V[i]);
tmpField = (char*)malloc(sizeof(char)*(strlen(tmpNum)+1));
strcpy(tmpField,tmpNum);
}
else if (select_dp->T[i] == 4 || select_dp->T[i] == 7 )
{
/*sprintf(tmpField,"%*.2f", (int)select_dp->L[i],*(float *)select_d
p->V[i]);*/
sprintf(tmpNum, "%f",*(float *)select_dp->V[i]);
tmpField = (char*)malloc(sizeof(char)*(strlen(tmpNum)+1));
strcpy(tmpField,tmpNum);
}
else
{
/*sprintf(tmpField,"%-*.*s",(int)select_dp->L[i],(int)select_dp->L[
i],select_dp->V[i]);
sprintf(tmpField, "%s",LRTrim(select_dp->V[i]));
*/
tmpField = (char*)malloc(sizeof(char)*((int)select_dp->L[i]+1));
memset(tmpField,0,select_dp->L[i]+1);
strncpy( tmpField, select_dp->V[i], select_dp->L[i] );
tmpField = LRTrim(tmpField);
}
}
tmpRow[i] = tmpField;
}/*inner loop end*/
if ( lRowCount == 0 )
tmpCtx = (char***)malloc(sizeof(char**)*(lRowCount+1));
else
tmpCtx = (char***)realloc(tmpCtx, sizeof(char**)*(lRowCount+1) );
tmpCtx[lRowCount] = tmpRow;
lRowCount ++;
}/*outer loop end*/
end_select_loop:
retDataSet->lRows = lRowCount;
retDataSet->content = tmpCtx;
/* Tell user how many rows processed.
計算處理了多少條記錄
printf("\n\n%d row%c processed.\n", sqlca.sqlerrd[2],
sqlca.sqlerrd[2] == 1 ? '\0' : 's');
*/
/* When done, free the memory allocated for
pointers in the bind and select descriptors.
釋放結(jié)合和選擇描述區(qū)中為指針分配的存儲空間*/
for (i = 0; i < MAX_ITEMS; i++)
{
if (bind_dp->V[i] != (char *) 0)
{
free(bind_dp->V[i]);
}
if (select_dp->V[i] != (char *) 0)
free(select_dp->V[i]);
}
/* Free space used by the descriptors themselves.
釋放SQLDA所用的空間*/
sqlclu(bind_dp);
sqlclu(select_dp);
EXEC SQL WHENEVER SQLERROR CONTINUE;
/* Close the cursor. */
EXEC SQL CLOSE C;
/*提交并釋放數(shù)據(jù)庫*/
EXEC SQL COMMIT WORK RELEASE;
return 0;
sql_error:
for (i = 0; i < MAX_ITEMS; i++)
{
if (bind_dp->V[i] != (char *) 0)
{
free(bind_dp->V[i]);
}
if (select_dp->V[i] != (char *) 0)
free(select_dp->V[i]);
}
sqlclu(bind_dp);
sqlclu(select_dp);
printf("%s\n",sqlca.sqlerrm.sqlerrmc);
sprintf(errMsg,"%s",sqlca.sqlerrm.sqlerrmc);
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL ROLLBACK WORK;
return -1;
}
void printDataSet(DataSet ds)
{
int i;
long l;
printf( "\nDATA SET \n" );
printf( "**** Field Info ****\n\n" );
for ( i = 0 ; i< ds.iCols; i++ )
{
if( i>0 )
printf( "," );
printf( "%s", ds.fields[i] );
}
printf( "\n\n**** Content Info ****\n\n" );
for ( l=0; l<ds.lRows; l++ )
{
for( i=0; i<ds.iCols; i++ )
{
if( i>0 )
printf(",");
printf("%s", ds.content[l][i] );
}
printf("\n");
}
}
void freeDataSet(DataSet ds )
{
long l;
int i;
/*free content area*/
if ( ds.content!=NULL )
{
for ( l=0; l<ds.lRows; l++ )
{
if( ds.content[l]!=NULL )
{
for( i=0; i<ds.iCols; i++ )
{
if( ds.content[l][i]!=NULL )
free(ds.content[l][i]);
ds.content[l][i] = NULL;
}
free(ds.content[l]);
ds.content[l] = NULL;
}
}
free(ds.content);
ds.content = NULL;
}
/*free fields area*/
if( ds.fields!=NULL )
{
for( i=0; i<ds.iCols; i++ )
{
if( ds.fields[i]!=NULL )
free(ds.fields[i]);
ds.fields[i]=NULL;
}
free(ds.fields);
ds.fields = NULL;
}
ds.lRows=0;
ds.iCols=0;
}
int getColNoByName(DataSet ds, char* colName)
{
int i=0;
char tmpColName[60];
char tmpDotColName[60];
if ( colName==NULL )
return -1;
if( strlen(colName)>50 )
return -1;
strcpy( tmpColName, colName );
upperStr( tmpColName );
sprintf(tmpDotColName, ".%s", tmpColName );
for( ; i<ds.iCols; i++ )
{
if( ds.fields[i]==NULL )
return -1;
if( strcmp( tmpColName, ds.fields[i] )==0 || strstr(ds.fields[i],tmpDotColName)!=NULL )
return i;
}
return -1;
}
char* elementAt(DataSet ds, long lRow, char* colName)
{
int i=0;
/*行越界*/
if( ds.lRows<lRow )
return NULL;
/*列越界*/
i = getColNoByName( ds, colName );
if( i==-1 )
return NULL;
if( ds.content==NULL )
return NULL;
if( ds.content[lRow]==NULL )
return NULL;
return ds.content[lRow][i];
}
int setElementAt(DataSet ds, long lRow, int iCol, char* value)
{
if( ds.lRows<lRow || ds.iCols<iCol )
return -1;
if( ds.content==NULL )
return -1;
if( ds.content[lRow]==NULL )
return -1;
if( value==NULL )
{
if( ds.content[lRow][iCol]!=NULL )
{
free(ds.content[lRow][iCol]);
ds.content[lRow][iCol] = NULL;
}
return 0;
}
if( ds.content[lRow][iCol]==NULL ){
ds.content[lRow][iCol] = malloc(sizeof(char)*(strlen(value)+1));
strcpy(ds.content[lRow][iCol], value);
}else
{
ds.content[lRow][iCol] = realloc(ds.content[lRow][iCol], sizeof(char)*(strlen(value)+1));
strcpy(ds.content[lRow][iCol], value);
}
return 0;
}
main(argc, argv)
int argc;
char *argv[];
{
DataSet ds;
char errMsg[2048];
if ( argc<2 )
{
printf("Usage OraDBUtil SQL \n");
exit(0);
}
/*執(zhí)行查詢*/
if( strncmp("SELECT", argv[1], 6 )==0 )
{
if( execQuery(argv[1], &ds, errMsg)!= 0 )
{
printf("err:%s", errMsg );
exit(1);
}
/*打印查詢結(jié)果*/
printDataSet(ds);
/*根據(jù)列名查找 列數(shù)*/
printf("the col: %s 's colNo is: %d\n","menu_title", getColNoByName(ds, "menu_title" ) );
/*根據(jù)行號,列名查找值*/
printf("the rowNo: %d colName: %s 's value is: %s\n", 0,"menu_title", elementAt(ds, 0, "menu_title" ) );
/*設(shè)置某一單元的值*/
setElementAt(ds, 0, 6, "WISEKING");
/*根據(jù)行號,列名查找值*/
printf("after set, the rowNo: %d colNo: %d 's value is: %s\n", 0, 6 , ds.content[0][6] );
/*釋放結(jié)果集*/
freeDataSet(ds);
}else
execUpdate(argv[1]); /*執(zhí)行變更,包括INSERT,UPDATE,DELETE*/
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -