📄 cursor.cpp
字号:
static const char* sccsid = "@(#)cursor.cpp v1.0.0 2000-08-28";
/* Copyright(C) 1999, 2000 by JiangSu Bell Software CO.,LTD. */
/*
Name: cursor.cpp Version: 1.0.0
Created by HanBing Date: 2000-08-08
Comment: Our group defining all base-class sets
Modified:
2) 2000-08-28 HanBing - Modifed the Cursor be array_size;
1) 2000-08-08 HanBing - Create;
*/
#include "common.h"
#include "field.hpp"
#include "Connection.hpp"
#include "cursor.hpp"
const int DEFER_PARSE = 1;
const int VERSION_7 = 2;
/* open the Cursor */
State Cursor :: Open( XW_Connection *conn )
{
if ( state == opened )
Close();
int status = oopen( &cda, &conn->lda, NULL, -1, -1, NULL, -1 );
if ( status == 0 ) // successfull open
{
state = opened;
connect = conn;
}
else
ReportError();
return state;
}
/* close the Cursor */
State Cursor :: Close()
{
if ( state == opened )
{
int status = oclose( &cda );
if ( status == 0 ) // successful Cursor close
{
state = closed;
connect = NULL;
}
}
return state;
}
/* bind an input variable */
int Cursor :: BindCol( CField* Field )
{
int result = 1;
text *name = new text [ strlen( Field->Name() ) + 2 ];
sprintf( (char*)name, ":%s", Field->Name() );
sb2* Bind = Field->State();
switch ( Field->Type() )
{
case CharT:
result = obndrv( &cda, name, -1, Field->Buff(), Field->LineLen(), SQLT_STR, -1, Bind, 0, -1, -1 );
break;
case IntT:
result = obndrv( &cda, name, -1, Field->Buff(), Field->LineLen(), SQLT_INT, -1, Bind, 0, -1, -1 );
break;
case FloatT:
result = obndrv( &cda, name, -1, Field->Buff(), Field->LineLen(), SQLT_FLT, -1, Bind, 0, -1, -1 );
break;
}
delete name;
return ( 1 - result );
}
/* define an output variable */
int Cursor :: DefineCol( int position, CField* Field )
{
int result = 1;
sb2* Bind = Field->State();
position++;
switch ( Field->Type() )
{
case CharT:
result = odefin( &cda, position, Field->Buff(), Field->LineLen(), SQLT_STR, -1,
Bind, (text*)0, -1, -1, (ub2*)0, (ub2*)0 );
break;
case IntT:
result = odefin( &cda, position, Field->Buff(), Field->LineLen(), SQLT_INT, -1,
Bind, (text*)0, -1, -1, (ub2*)0, (ub2*)0 );
break;
case FloatT:
result = odefin( &cda, position, Field->Buff(), Field->LineLen(), SQLT_FLT, -1,
Bind, (text*)0, -1, -1, (ub2*)0, (ub2*)0 );
break;
}
return ( 1 - result );
}
int Cursor :: Describe( int position, CField* &Field )
{
sb4 size = 0;
short type;
sb4 len = 256, dsize = 0;
short prec = 0, scale = 0, nullok = 0;
char *buf = new char [len];
int j = 0;
if ( odescr( &cda, position+1, &size, &type, (sb1*)buf, &len, &dsize, &prec, &scale, &nullok ) )
{
if ( cda.rc == VAR_NOT_IN_LIST )
j = 0;
else
j = -1;
}
else
{
j = 1;
buf[ len ] = '\0';
DataType tmp_type = VoidT;
switch ( type )
{
case SQLT_CHR: /* 1 (ORANET TYPE) character string */
case SQLT_STR: /* 5 zero terminated string */
case SQLT_VCS: /* 9 Variable character string */
case SQLT_NON: /* 10 Null/empty PCC Descriptor entry */
case SQLT_RID: /* 11 rowid */
case SQLT_DAT: /* 12 date in oracle format */
case SQLT_VBI: /* 15 binary in VCS format */
case SQLT_BIN: /* 23 binary data(DTYBIN) */
case SQLT_LBI: /* 24 long binary */
case SQLT_SLS: /* 91 Display sign leading separate */
case SQLT_LVC: /* 94 Longer longs (char) */
case SQLT_LVB: /* 95 Longer long binary */
case SQLT_AFC: /* 96 Ansi fixed char */
case SQLT_AVC: /* 97 Ansi Var char */
case SQLT_CUR: /* 102 cursor type */
case SQLT_RDD: /* 104 rowid descriptor */
case SQLT_LAB: /* 105 label type */
case SQLT_OSL: /* 106 oslabel type */
if ( type == SQLT_RID )
size = 9;
if ( type == SQLT_DAT )
size = 18;
tmp_type = CharT;
break;
case SQLT_NUM: /* 2 (ORANET TYPE) oracle numeric */
case SQLT_FLT: /* 4 (ORANET TYPE) Floating point number */
case SQLT_PDN: /* 7 (ORANET TYPE) Packed Decimal Numeric */
tmp_type = FloatT;
break;
case SQLT_INT: /* 3 (ORANET TYPE) integer */
case SQLT_VNU: /* 6 NUM with preceding length byte */
case SQLT_LNG: /* 8 long */
case SQLT_UIN: /* 68 unsigned integer */
tmp_type = IntT;
break;
}
//cao
// if( type == SQLT_NUM && len < 8 && scale == 0 )
// tmp_type = IntT;
Field = new CField( buf, tmp_type, short(size), 0, n_cur_size );
}
delete buf;
return j;
}
bool Cursor :: Parse( const char *stmt )
{
// cout << "sql=" << stmt << endl << flush;
if ( oparse( &cda, (text*)stmt, (sb4)-1, DEFER_PARSE, (ub4) VERSION_7 ) )
{
ReportError();
return false;
}
else
return true;;
}
long Cursor :: ReportMsg( int j )
{
long i = 0;
if ( j )
{
ReportError();
if ( cda.rc == NO_DATA_FOUND )
{
if ( cda.rpc > 0 )
i = cda.rpc;
else
i = 0;
}
else
{
i = -cda.rc;
Close();
}
}
else
{
if ( cda.rpc > 0 )
i = cda.rpc;
else
i = 1;
}
return i;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -