📄 oracledemounit.cpp
字号:
// Direct Oracle Access - Oracle demo
// Allround Automations
// support@allroundautomations.nl
// http://www.allroundautomations.nl
//
// This application demonstrates:
// - Executing user-defined queries
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop
#include "OracleDemoUnit.h"
//---------------------------------------------------------------------------
#pragma link "Grids"
#pragma link "Oracle"
#pragma link "OracleData"
#pragma resource "*.dfm"
TOracleDemoForm *OracleDemoForm;
//---------------------------------------------------------------------------
__fastcall TOracleDemoForm::TOracleDemoForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TOracleDemoForm::ClearGrid()
{
int r, c;
for (c = 0; c < Grid->ColCount; c++)
for (r = 0; r < Grid->RowCount; r++)
Grid->Cells[c][r] = "";
Grid->ColCount = 2;
Grid->RowCount = 2;
}
//---------------------------------------------------------------------------
void __fastcall TOracleDemoForm::LogonBtnClick(TObject *Sender)
{
if (LogonBtn->Down) OracleLogon->Execute(); else Session->LogOff();
LogonBtn->Down = Session->Connected;
ExecBtn->Enabled = Session->Connected;
CommitBtn->Enabled = Session->Connected;
RollbackBtn->Enabled = Session->Connected;
}
//---------------------------------------------------------------------------
void __fastcall TOracleDemoForm::CommitBtnClick(TObject *Sender)
{
Session->Commit();
}
//---------------------------------------------------------------------------
void __fastcall TOracleDemoForm::RollbackBtnClick(TObject *Sender)
{
Session->Rollback();
}
//---------------------------------------------------------------------------
void __fastcall TOracleDemoForm::ExecBtnClick(TObject *Sender)
{
int Row, Column;
ClearGrid();
// Copy the SQL statement in the memo to the query and try to execute it
Query->Clear();
Query->SQL->Add(QueryMemo->Text);
try
{
Query->Execute();
// Place the fieldnames into the first row of the grid
if (Query->FieldCount() >= Grid->ColCount) Grid->ColCount = Query->FieldCount() + 1;
for (Column = 1; Column <= Query->FieldCount(); Column++)
Grid->Cells[Column][0] = Query->FieldName(Column - 1);
// Place the data into the grid
Row = 1;
while (!Query->Eof)
{
Grid->Cells[0][Row] = IntToStr(Row);
for (Column = 1; Column <= Query->FieldCount(); Column++)
Grid->Cells[Column][Row] = Query->Field(Column - 1);
Row++;
Query->Next();
}
if (Row > Grid->RowCount) Grid->RowCount = Row;
// Show the execution status
switch(Query->FunctionType())
{
case 4: StatusBar->SimpleText = IntToStr(Query->RowsProcessed()) + " Rows selected"; break;
case 5: StatusBar->SimpleText = IntToStr(Query->RowsProcessed()) + " Rows updated"; break;
case 9: StatusBar->SimpleText = IntToStr(Query->RowsProcessed()) + " Rows deleted"; break;
default : StatusBar->SimpleText = "Done"; break;
}
}
catch (EOracleError &E)
{
// Show Oracle error in message box and status bar
Application->ShowException(&E);
StatusBar->SimpleText = E.Message;
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -