 | | Wide Studio Object Reference
| |
Class Name
WSCvodbc
Specification of methods
open Function Description
- Form
- long open(char* dsn,char* username,char* passwd)
- Function
- Connect to database
- Description
- Connect to database using ODBC
- Parameters
-
(in)char* dsn | Specify DSN name |
(in)char* username | Specify a user name to connect |
(in)char* passwd | Specify a password |
- Return value
- WS_NO_ERR:Success, WS_ERR:Fail
- Notice
- None.
- Samples
-
long ret = newvodb_000->open("postgres","user","passwd");
if (ret == WS_NO_ERR){
//Connect
}else{
//Connection filed. Obtain an error message
char buffer[1024];
newvodb_000->getErrorMsg(buffer,1024);
}
open Function Description
- Form
- long open()
- Function
- Connect to database
- Description
- Connect to dabase using property value.
- Parameters
- None
- Return value
- WS_NO_ERR:Success, WS_ERR:Fail
- Notice
- None
- Samples
-
long ret = newvodb_000->open();
if (ret == WS_NO_ERR){
//Connect
}else{
//Connecation failed. Obtain an error message
char buffer[1024];
newvodb_000->getErrorMsg(buffer,1024);
}
close Function Description
- Form
- long close()
- Function
- Cut off a connection to database
- Description
- Cut off a connection to database using ODBC
- Parameters
- None.
- Return value
- WS_NO_ERR:Success, WS_ERR:Fail
- Notice
- None.
- Samples
-
long ret = newvodb_000->close();
if (ret == WS_NO_ERR){
//Disconnect succeeded
}else{
//Disconnect failed. Obtain an error message
char buffer[1024];
newvodb_000->getErrorMsg(buffer,1024);
}
isOpen Function Description
- Form
- WSCbool isOpen()
- Function
- Obtain status of database connection
- Description
- Obtain status of database connection using ODBC
- Parameters
- None.
- Return value
- True:Connecting, False:Disconnecting
- Notice
- None
- Samples
-
WSCbool ret = newvodb_000->isOpen();
if (ret == False){
//Disconnecting
}else{
//Connecting
}
sqlExecute Function Description
- Form
- long sqlExecute(const char* sql)
- Function
- Issue SQL syntax against database
- Description
- Issue SQL syntax against database using ODBC
- Parameters
-
(in)const char* sql | Specify SQL syntax |
- Return value
- WS_NO_ERR:Success,WS_ERR:Fail
- Notice
- The result from SQL can be accessed by using WSCodbcRecord class.
- Samples
-
//Create a table and store data
char buf1[1024];
strcpy(buf1, "drop table shinamono");
long ret = newvodb_000->sqlExecute(buf1);
strcpy(buf1,"create table shinamono(code int, hinmei char(20), nedan float)");
newvodb_000->sqlExecute(buf1);
newvodb_000->beginTran();
strcpy(buf1,"insert into shinamono values(1, 'Orange', 100)");
newvodb_000->sqlExecute(buf1);
strcpy(buf1,"insert into shinamono values(2, 'Apple', 200)");
newvodb_000->sqlExecute(buf1);
strcpy(buf1,"insert into shinamono values(3, 'Banana', 300)");
newvodb_000->sqlExecute(buf1);
strcpy(buf1,"insert into shinamono values(4, 'Melon', 0)");
newvodb_000->sqlExecute(buf1);
newvodb_000->commitTran();
//Refer to data
WSCodbcRecord rs(newvodb_000);
char var[256];
WSCstring result;
newvodb_000->beginTran();
if(rs.open("select * from shinamono order by code") == WS_NO_ERR) {
while (!rs.isEOF()) {
rs.getColValue("code", &var);
int code = (int)var;
result << "code:" << (int)var << " ";
rs.getColValue("hinmei", &var);
result << "hinmei:" << (char*)var << " ";
rs.getColValue("nedan", &var);
char buf[80];
double nedan = (float)var + 10;
sprintf(buf, "%f", (float)var);
result << "nedan:" << buf << "\n";
}
printf("result:\n%s",(char*)result);
}
beginTran Function Description
- Form
- long beginTran()
- Function
- Start transaction
- Description
- Start transaction using ODBC
- Parameters
- None
- Return value
- WS_NO_ERR:Success, WS_ERR:Fail
- Notice
- Database should be connected beforehand
- Samples
-
long ret = newvodb_000->beginTran();
if (ret == WS_NO_ERR){
//Transaction start success
}else{
//Transaction start failed. Obtain an error message
char buffer[1024];
newvodb_000->getErrorMsg(buffer,1024);
}
commitTran Function Description
- Form
- long commitTran()
- Function
- Commit a transaction
- Description
- Commit a transaction using ODBC
- Parameters
- None
- Return value
- WS_NO_ERR:Success, WS_ERR:Fail
- Notice
- Database should be connected beforehand
- Samples
-
long ret = newvodb_000->commitTran();
if (ret == WS_NO_ERR){
//Transaction commit succceeded
}else{
//Transaction commit failed. Obtain an error message
char buffer[1024];
newvodb_000->getErrorMsg(buffer,1024);
}
abortTran Function Description
- Form
- long abortTran()
- Function
- Abort transaction
- Description
- Abort transaction using ODBC
- Parameters
- None
- Return value
- WS_NO_ERR:Sueccess, WS_ERR:Fail
- Notice
- Database should be connected beforehand
- Samples
-
long ret = newvodb_000->abortTran();
if (ret == WS_NO_ERR){
//Transaction abortion succeeded
}else{
//Transaction abortion failed. Obtain an error.
char buffer[1024];
newvodb_000->getErrorMsg(buffer,1024);
}
getErrorMsg Function Description
- Form
- long getErrorMsg(char* buffer,long buflen)
- Function
- Obtain error strings
- Description
-
- Parameters
-
(in/out)char* buf | Buffer to store error strings |
(in)long buflen | Specify a buffer length |
- Return value
- None.
- Notice
-
- Samples
- Refer to open sample.
Document Release 3.0 For Use with Wide Studio Release 3.0, Summer 2002 Wide Stuido Home | Up to Copyright(C) T. Hirabayashi, 1999-2002 | | Last modified: July 15, 2002 | |