📄 connection.cpp
字号:
static const char* sccsid = "@(#)XW_Connection.cpp v1.0.0 2000-08-08";
/* Copyright(C) 1999, 2001 by JiangSu Bell Software CO.,LTD. */
/*
Name: XW_Connection.cpp Version: 1.0.0
Created by HanBing Date: 2000-08-08
Comment: Class for connect to Database
Modified:
1) 2000-08-08 HanBing - Create;
*/
#include "common.h"
#include "field.hpp"
#include "Connection.hpp"
#include "cursor.hpp"
/*
Class: XW_Connection Version: 1.0
Created by HanBing Date: 2000-08-08
Definition File: XW_Connection.h
Comment:
Modified:
1) 2000-08-08 HanBing - Create;
*/
/*
Name: XW_Connection() - constructor
Create by HanBing Date: 2000-08-08
Define in Class: XW_Connection File: XW_Connection.h
Comment:
Parameters:
Return Value:
Modified:
1) 2000-08-08 HanBing - Create;
*/
XW_Connection :: XW_Connection()
{
state = closed;
memset( hda, '\0', HDA_SIZE );
memset( pcMessage, '\0', 1024 );
}
/*
Name: Login()
Create by HanBing Date: 2000-08-08
Define in Class: XW_Connection File: XW_Connection.h
Comment: connect to the database server
Parameters: server - input - database_server's name,
the function get the username, password, connect string
from the profile's section which name is server
Return Value: if connect to server successful, return 1,
else returb 0;
Modified:
1) 2000-08-08 HanBing - Create;
*/
//2003.10.8
int InitFlag = 0;
//
int XW_Connection :: Login( const char *server )
{
char user[50] = "user_name";
char pass[20] = "password";
char constr[20] = "";
if ( !GetProfileStr( ".config.ini", server, "UserName", (char*)user ) )
WriteProfileStr( ".config.ini", server, "UserName", (char*)user );
if ( !GetProfileStr( ".config.ini", server, "PassWord", (char*)pass ) )
WriteProfileStr( ".config.ini", server, "PassWord", (char*)pass );
if ( !GetProfileStr( ".config.ini", server, "ConnectString", (char*)constr ) )
WriteProfileStr( ".config.ini", server, "ConnectString", (char*)constr );
if ( strlen( constr ) )
{
strcat( user, "@" );
strcat( user, constr );
}
//2003.10.8
if ( !InitFlag )
{
opinit( OCI_EV_TSF );
InitFlag = 1;
}
//
if ( state == opened )
Logout();
int status = olog( &lda, hda, (text*)user, -1, (text*)pass, -1, NULL, -1, OCI_LM_DEF );
if ( status == 0 ) // successful login
state = opened;
else
{
text pc_msg[256];
oerhms( &lda, lda.rc, pc_msg, 256 );
sprintf( pcMessage, "Connect to Oracle DB Failed:\n%s\nExit!", pc_msg );
}
Assert( state == opened, pcMessage );
return state;
}
/*
Name: Logout()
Create by HanBing Date: 2000-08-08
Define in Class: XW_Connection File: XW_Connection.h
Comment: disconnect from the database server
Parameters:
Return Value: the connnection's state
Modified:
1) 2000-08-08 HanBing - Create;
*/
int XW_Connection :: Logout()
{
if ( state == opened ) // has connected
{
if ( ologof( &lda ) == 0 ) // successful logout
state = closed;
}
return state;
}
/*
Name: ExecSql()
Create by HanBing Date: 2000-08-08
Define in Class: XW_Connection File: XW_Connection.h
Comment:
Parameters:
Return Value:
Modified:
1) 2000-08-08 HanBing - Create;
*/
long XW_Connection :: ExecSql( char *sql )
{
Cursor cursor;
long j = -1;
cursor.Open( this );
if ( cursor.IsOpen() )
{
if ( cursor.Parse( sql ) )
j = cursor.Execute();
cursor.Close();
}
else
ReportError( lda.rc );
return j;
}
/*Commit a Transaction action*/
int XW_Connection :: Commit()
{
int j = ocom( &lda );
if ( j )
{
ReportError( lda.rc );
j = -1;
}
else
j = 1;
return j;
}
/*Rollback a Transaction action*/
int XW_Connection :: Rollback()
{
int j = orol( &lda );
if ( j )
{
ReportError( lda.rc );
j = -1;
}
else
j = 1;
return j;
}
XW_Connection DefaultConnect;
bool ReadTime( char *Date, char *Time )
{
static Cursor TimCur;
if ( !TimCur.IsOpen() )
{
TimCur.Open( &DefaultConnect );
if ( TimCur.IsOpen() )
{
if ( !TimCur.Parse( "select to_char(sysdate,'YYYYMMDD') DATT, to_char(sysdate,'hh24miss') TIMM from dual" ) )
TimCur.Close();
}
}
bool ret = false;
static CField Datt( "DATT", CharT, 9 );
static CField Timm( "TIMM", CharT, 7 );
if ( TimCur.IsOpen() )
{
int j = TimCur.Execute();
if ( j > 0 )
j = TimCur.DefineCol( 0, &Datt );
if ( j > 0 )
j = TimCur.DefineCol( 1, &Timm );
if ( j > 0 )
j = TimCur.Fetch();
if ( j > 0 )
ret = true;
}
if ( ret )
{
strcpy( Date, Datt.Char() );
strcpy( Time, Timm.Char() );
}
else
TimCur.ReportError();
return ret;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -