.#include <sqlrelay/sqlrclientwrapper.h>
#include <stdio.h>
main() {
int i,j;
sqlrcon con=sqlrcon_alloc("host",9000,"","user","password",0,1);
sqlrcur cur=sqlrcur_alloc(con);
sqlrcur_prepareQuery(cur,"begin :curs:=sp_mytable; end;");
sqlrcur_defineOutputBindCursor(cur,"curs");
sqlrcur_executeQuery(cur);
sqlrcur bindcur=sqlrcur_getOutputBindCursor(cur,"curs");
sqlrcur_fetchFromBindCursor(bindcur);
// print fields from table
for (i=0; i<sqlrcur_rowCount(bindcur); i++) {
for (j=0; j<sqlrcur_colCount(bindcur); j++) {
printf("%s,",sqlrcur_getFieldByIndex(bindcur,i,j));
}
printf("\n");
}
sqlrcur_free(bindcur);
sqlrcur_free(cur);
sqlrcon_free(con);
}
The number of cursors simultaneously available per-connection is set at compile time and defaults to 5. Getting Column Information
For each column, the API supports getting the name, type and length of each field. All databases support these attributes. The API also supports getting the precision, scale, length of the longest field, and whether the column is nullable, the primary key, unique, part of a key, unsigned, zero-filled, binary, or an auto-incrementing field. However, not all databases support these attributes. If a database doesn''''t support an attribute, it is always returned as false. #include <sqlrelay/sqlrclientwrapper.h>
#include <stdio.h>
main() {
int i;
sqlrcon con=sqlrcon_alloc("host",9000,"","user","password",0,1);
sqlrcur cur=sqlrcur_alloc(con);
sqlrcur_sendQuery(cur,"select * from my_table");
sqlrcon_endSession(con);
for (i=0; i<sqlrcur_colCount(cur); i++) {
printf("Name: %s\n",sqlrcur_getColumnName(cur,i));
printf("Type: %s\n",sqlrcur_getColumnType(cur,i));
printf("Length: %d\n",sqlrcur_getColumnLength(cur,i));
printf("Precision: %d\n",sqlrcur_getColumnPrecision(cur,i));
printf("Scale: %d\n",sqlrcur_getColumnScale(cur,i));
printf("Longest Field: %d\n",sqlrcur_getLongest(cur,i));
printf("Nullable: %d\n",sqlrcur_getColumnIsNullable(cur,i));
printf("Primary Key: %d\n",sqlrcur_getColumnIsPrimaryKey(cur,i));
printf("Unique: %d\n",sqlrcur_getColumnIsUnique(cur,i));
printf("Part of Key: %d\n",sqlrcur_getColumnIsPartOfKey(cur,i));
printf("Unsigned: %d\n",sqlrcur_getColumnIsUnsigned(cur,i));
printf("Zero Filled: %d\n",sqlrcur_getColumnIsZeroFilled(cur,i));
printf("Binary: %d\n",sqlrcur_getColumnIsBinary(cur,i));
printf("Auth Increment:%d\n",sqlrcur_getColumnIsAutoIncrement(cur,i));
printf("\n");
}
sqlrcur_free(cur);
sqlrcon_free(con);
}
Some databases force column names to upper case, others force column names to lower case, and others still support mixed-case column names. Sometimes, when migrating between databases, you can run into trouble. You can use upperCaseColumnNames() and lowerCaseColumnNames() to cause column names to be converted to upper or lower case, or you can use mixedCaseColumnNames() to cause column names to be returned in the same case as they are defined in the database. #include <sqlrelay/sqlrclientwrapper.h>
#include <stdio.h>
main() {
int i;
sqlrcon con=sqlrcon_alloc("host",9000,"","user","password",0,1);
sqlrcur cur=sqlrcur_alloc(con);
// column names will be forced to upper case
sqlrcur_upperCaseColumnNames(cur);
sqlrcur_endQuery(cur,"select * from my_table");
sqlrcon_endSession(con);
for (i=0; i<sqlrcur_colCount(c上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>
|