Proud::COdbcCommand Class Reference

Public Member Functions

PROUDSRV_API void Prepare (COdbcConnection &conn, const String &query)
 
PROUDSRV_API void AppendInputParameter (const COdbcVariant &param, OdbcSqlDataType sqlType=OdbcSqlDataType_UNKNOWN)
 
PROUDSRV_API void AppendOutputParameter (const COdbcVariant &param, OdbcSqlDataType sqlType=OdbcSqlDataType_UNKNOWN)
 
PROUDSRV_API void AppendInputOutputParameter (const COdbcVariant &param, OdbcSqlDataType sqlType=OdbcSqlDataType_UNKNOWN)
 
PROUDSRV_API void SetNullParameter (unsigned int paramIndex, bool state)
 
PROUDSRV_API int Execute (COdbcWarnings *odbcWarnings=NULL)
 
PROUDSRV_API int Execute (COdbcRecordset &recordset, COdbcWarnings *odbcWarnings=NULL)
 

Detailed Description

It is a class that deals with Prepared Statement. It is useful for continuous use by changing parameter value of a query, differently from Execute in COdbcConnection. Also used when executing Stored Procedure that Input, Output and Input&Output parameter need.

Member Function Documentation

PROUDSRV_API void Proud::COdbcCommand::AppendInputOutputParameter ( const COdbcVariant param,
OdbcSqlDataType  sqlType = OdbcSqlDataType_UNKNOWN 
)

It is used when designating “Input&Output parameter”. You can only input data in the form of pointer in order to receive data. In case of inputting in the form of pointer, you must check if there is problem occurred by scope of the relevant variable.

  1. int a;
  2. cmd.AppendInputOutputParameter(&a);

Depending on inputted data, sqlType is automatically decided, so in case you input a type you want in the database, you can input OdbcSqlDataType. ex> In case of inputting & outputting variable whose type is int32_t as data whose type is int64_t,

  1. int a;
  2. cmd.AppendInputOutputParameter(a, OdbcSqlDataType_BIGINT);

In case of inputting & outputting string, you must use GetBuffer와 ReleaseBuffer of Proud::String class before/after execution.

  1. String str;
  2. str = "ABCD"; // 2 and 3 must be right order.
  3. str.GetBuffer(100);
  4. cmd.AppendInputOutputParameter(&str);
  5. cmd.Execute();
  6. str.ReleaseBuffer();
  7. str = "EFGH"; // You must repeat 2,3,5 and 6.
  8. str.GetBuffer(100);
  9. cmd.Execute();
  10. str.ReleaseBuffer();

In case of receiving binary data, you must use Proud::COdbcByteData class. COdbcByteData is only allowed to be inputted by the pointer.

  1. unsigned char byte[10000];
  2. COdbcByteData byteData(byte, 0, 10000);
  3. cmd.AppendOutputParameter(&byteData);
  4. cmd.Execute();
PROUDSRV_API void Proud::COdbcCommand::AppendInputParameter ( const COdbcVariant param,
OdbcSqlDataType  sqlType = OdbcSqlDataType_UNKNOWN 
)

It is used when inputting “Input parameter”. You can just input data in the form of pointer in case you want to change variables only. In case of inputting in the form of pointer, you must check if there is problem occurred by scope of the relevant variable.

  1. int a = 10;
  2. cmd.AppendInputParameter(a); // It is executed in the form of Call by Value as “a” is copied.
  3. cmd.AppendInputParameter(&a); // It is executed in the form of Call by Pointer that uses “a” address.

Depending on inputted data, sqlType is automatically decided, so in case you input a type you want in the database, you can input OdbcSqlDataType. ex> In case of inputting variable whose type is int32_t as data whose type is int64_t,

  1. int a = 10;
  2. cmd.AppendInputParameter(a, OdbcSqlDataType_BIGINT);

In case of inputting binary data, you must use Proud::COdbcByteData class. COdbcByteData is only allowed to be inputted by the pointer.

  1. unsigned char byte[10000] = "........................."; // Input 1,000 byte data.
  2. COdbcByteData byteData(byte, 1000, 10000);
  3. cmd.AppendInputParameter(&byteData);
PROUDSRV_API void Proud::COdbcCommand::AppendOutputParameter ( const COdbcVariant param,
OdbcSqlDataType  sqlType = OdbcSqlDataType_UNKNOWN 
)

It is used when designating “Output parameter”. You can only input data in the form of pointer in order to receive data. In case of inputting in the form of pointer, you must check if there is problem occurred by scope of the relevant variable.

  1. int a;
  2. cmd.AppendOutputParameter(&a);

Depending on inputted data, sqlType is automatically decided, so in case you input a type you want in the database, you can input OdbcSqlDataType. ex> In case of receiving data whose type is int64_t as variable whose type is int32_t,

  1. int a;
  2. cmd.AppendOutputParameter(a, OdbcSqlDataType_BIGINT);

In case of receiving string, you must use GetBuffer와 ReleaseBuffer of Proud::String class before/after execution.

  1. String str;
  2. str.GetBuffer(100);
  3. cmd.AppendOutputParameter(&str);
  4. cmd.Execute();
  5. str.ReleaseBuffer();
  6. str.GetBuffer(100); // You must repeat 2, 4 and 5.
  7. cmd.Execute();
  8. str.ReleaseBuffer();

In case of receiving binary data, you must use Proud::COdbcByteData class. COdbcByteData is only allowed to be inputted by the pointer.

  1. unsigned char byte[10000];
  2. COdbcByteData byteData(byte, 0, 10000);
  3. cmd.AppendOutputParameter(&byteData);
  4. cmd.Execute();
PROUDSRV_API int Proud::COdbcCommand::Execute ( COdbcWarnings odbcWarnings = NULL)

Execute the query.

PROUDSRV_API int Proud::COdbcCommand::Execute ( COdbcRecordset recordset,
COdbcWarnings odbcWarnings = NULL 
)

Execute the query.

Parameters
recordsetIt is a Recordset object that is received after query execution.
PROUDSRV_API void Proud::COdbcCommand::Prepare ( COdbcConnection conn,
const String query 
)

It is used when inputting a query. Input the query as ?. (ex> INSERT INTO test(id, name) VALUES(?, ?)). Table name and field name cannot be inputted as ?.

Parameters
connCOdbcConnection Object
queryQuery
PROUDSRV_API void Proud::COdbcCommand::SetNullParameter ( unsigned int  paramIndex,
bool  state 
)

Set a parameter as NULL. In case you want to input data as NULL in the database, change the status of NULL to TRUE by using this function. Once setting is done, the status is continuously used, so in case of restring the status, you must reset it as FALSE after execution.

Parameters
paramIndexparameter Index (ex> 1, 2, 3, ...)
statetrue or false