联通接收发送新程序
源代码在线查看: table.hpp
/* Copyright(C) 1999, 2000 by JiangSu Bell Software CO.,LTD. */
/*
Name: table.hpp Version: 2.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 class CTable for array operate;
1) 2000-08-08 HanBing - Create;
*/
#ifndef __TABLE__
#define __TABLE__
/* Indicate the operate on a table */
typedef enum
{
op_null = 0,
op_query,
op_insert,
op_update,
op_delete
} OpTable;
/*
Class: CTable Version: 2.0
Created by HanBing Date: 2000-08-08
Implementation File: table.cpp
Comment:
Modified
2) 2000-08-28 HanBing - Modifed for array operate;
1) 2000-08-08 HanBing - Create;
*/
class CTable
{
public:
/*
Name: CTable() - constructor
Comment:
Parameters: conn - input - the XW_Connection to be used
size - input - the row array size
Return Value:
Modified:
2) 2000-08-28 HanBing - Added parameter size for array operate;
1) 2000-08-08 HanBing - Create;
*/
CTable( XW_Connection& conn = DefaultConnect, uint size = 1 )
{
connect = &conn;
TableName = NULL;
op_tab = op_null;
is_query = false;
BatSize = size;
CurPos = 0;
nRow = 0;
pcIndex = NULL;
}
CTable( CTable& Tab )
{
connect = &Tab.Connect();
BatSize = Tab.Size();
op_tab = op_null;
is_query = false;
CurPos = 0;
nRow = 0;
pcIndex = NULL;
TableName = new char [ strlen( Tab.Name() ) + 1 ];
strcpy( TableName, Tab.Name() );
}
CTable( uint size )
{
CTable( DefaultConnect, size );
}
/*
Name: ~CTable() - destructor
Comment:
Parameters:
Return Value:
Modified:
1) 2000-08-08 HanBing - Create;
*/
~CTable()
{
if ( TableName )
delete TableName;
if ( pcIndex )
delete pcIndex;
}
uint Clear( bool flag = true )
{
FirstCol();
while ( CurCol() )
{
CurCol()->Clear( flag );
NextCol();
}
return ( CurPos = 0 );
}
/* functions for access columns */
long Flush( bool b_do = true, bool b_end = true )
{
if ( !TableName || !strlen( TableName ) )
return -1;
else if ( CurPos == 0 )
return 1;
long l_ret = 0;
if ( op_tab == op_null || !b_do ) /* no operate needed */
l_ret = Clear();
else if ( op_tab == op_insert )
l_ret = InsertTab();
else if ( op_tab == op_update )
l_ret = UpdateTab();
else if ( op_tab == op_delete )
l_ret = DeleteTab();
if ( b_end )
op_tab = op_null;
if ( BatSize > 1 && b_end )
Clear();
else
Clear( false );
return l_ret;
}
/* go to next row in the array */
/*
Name: Next()
Comment: go to next row in the array;
Parameters:
Return Value: the current position
Modified:
1) 2000-08-28 HanBing - Create;
*/
inline long Next()
{
long l_ret = 0;
if ( op_tab == op_null )
l_ret = Clear();
else if ( op_tab == op_query )
l_ret = QueryNext();
else if ( ++CurPos >= BatSize )
l_ret = Flush( true, false );
else
{
FirstCol();
while ( CurCol() )
{
CurCol()->Next();
NextCol();
}
l_ret = CurPos;
}
if ( BatSize == 1 && is_query )
op_tab = op_query;
return l_ret;
}
/* functions for query rows */
long Query( const char *condition = NULL );
long QuerybyIndex( T_LIST< CField >& Ind );
/* functions for modify data */
inline long Insert()
{
if ( BatSize > 1 )
Assert( ( op_tab == op_insert || op_tab == op_null ), "Can't Insert Now!" );
op_tab = op_insert;
return Next();
}
inline long Update()
{
if ( BatSize > 1 )
Assert( ( op_tab == op_update || op_tab == op_null ), "Can't Update Now!" );
op_tab = op_update;
return Next();
}
inline long Delete()
{
if ( BatSize > 1 )
Assert( ( op_tab == op_delete || op_tab == op_null ), "Can't Delete Now!" );
op_tab = op_delete;
return Next();
}
/* functions for set or get table attribute */
inline void SetTableName( const char* name )
{
if ( !name || !strlen( name ) || ( TableName && !strcmp( TableName, name ) ) )
return;
if ( TableName )
delete TableName;
TableName = new char [ strlen( name ) + 1 ];
strcpy( TableName, name );
QueryCursor.Close();
InsertCursor.Close();
UpdateCursor.Close();
DeleteCursor.Close();
}
inline const char* Name()
{
return TableName;
};
inline uint Size()
{
return BatSize;
};
/* functions for get the field's value */
inline CField& Field( const char* name )
{
FirstCol();
while ( CurCol() && strcmp( name, CurCol()->Name() ) )
{
NextCol();
}
Assert( CurCol() != NULL, name );
return *CurCol();
}
/* functions for access columns */
inline void FirstCol()
{
Fields.GoHead();
};
inline CField* NextCol()
{
return Fields.Next();
};
inline CField* CurCol()
{
return Fields.Current();
};
void PrintName();
/* Display the Fields in the current Buffer */
void Print();
inline XW_Connection& Connect() { return *connect; };
inline SetConnection( XW_Connection& conn = DefaultConnect )
{
connect = &conn;
}
protected:
CTable& operator = ( CTable& Tab )
{
FirstCol();
Tab.FirstCol();
while ( CurCol() && Tab.CurCol() )
{
*CurCol() = *Tab.CurCol();
NextCol();
Tab.NextCol();
}
return *this;
}
T_LIST< CField > Fields;
private:
XW_Connection *connect;
Cursor QueryCursor;
Cursor InsertCursor;
Cursor UpdateCursor;
Cursor DeleteCursor;
/* clear the array buffer */
/*
Name: Clear()
Comment: clear the array buffer
Parameters:
Return Value:
Modified:
1) 2000-08-28 HanBing - Create;
*/
long InsertTab();
long UpdateTab();
long DeleteTab();
bool ParseQuery( const char* );
long QueryNext();
OpTable op_tab;
bool is_query;
uint BatSize;
uint CurPos;
long CurSize;
long nRow;
char *TableName;
char *pcIndex;
//hyl on 20030922
char pcSQL[ 1024 ];
//
};
#endif //__TABLE__