My Question is about: wxDateTime,wxODBC,wxTextCtrl and .mdb

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Marcelo Paiva
In need of some credit
In need of some credit
Posts: 3
Joined: Thu Jan 14, 2010 1:49 pm
Location: Rua Guido Both s/n Quilombo/SC Brasil CEP89850000
Contact:

My Question is about: wxDateTime,wxODBC,wxTextCtrl and .mdb

Postby Marcelo Paiva » Thu Jan 14, 2010 6:07 pm

Thank you by oportunit,
My Emglish is bad!, I am brazilian, the Portuguese is most far from to English.
But, my question is about the use of the wxODBC to enter into file .mdb and .mdbs.
I get obtened sucessful on sql query to enter in .mdb with wxODBC,wxDEVC++(win32),wxButton with event wxButton with routine wxODBC sample adapted and wxTextCtrl(wxString) to show field long,int,Text but my failure and show field date and hour and wxTextCtrl, so, two cases:
1-I used c++ variable date how int type and convert operator 'wxString<<int or long' in the my wxTextCtrl been showed 'number int' and not format date to field date (showed 134234123 and not 12/01/2010).
2-I change date to wxDateTime, so been showed in the wxTextCtrl format date My Emglish is bad!, I am brazilian, the Portuguese is most far from to English.
But, my question is about the use of the wxODBC to enter into file .mdb and .mdbs.
I get obtened sucessful on sql query to enter in .mdb with wxODBC,wxDEVC++(win32),wxButton with event wxButton with routine wxODBC sample adapted and wxTextCtrl(wxString) to show field long,int,Text but my failure and show field date and hour and wxTextCtrl, so, two cases:
1-I used c++ variable date how int type and convert operator 'wxString<<int or long' in the my wxTextCtrl been showed 'number int' and not format date to field date (showed 134234123 and not 12/01/2010).
2-I change date to wxDateTime, so been showed in the wxTextCtrl format dateMy Emglish is bad!, I am brazilian, the Portuguese is most far from to English.
But, my question is about the use of the wxODBC to enter into file .mdb and .mdbs.
I get obtened sucessful on sql query to enter in .mdb with wxODBC,wxDEVC++(win32),wxButton with event wxButton with routine wxODBC sample adapted and wxTextCtrl(wxString) to show field long,int,Text but my failure and show field date and hour and wxTextCtrl, so, two cases:
1-I used c++ variable date how int type and convert operator 'wxString<<int or long' in the my wxTextCtrl been showed 'number int' and not format date to field date (showed 134234123 and not 12/01/2010).
2-I change date to wxDateTime, so been showed in the wxTextCtrl format date 08/20/71 but the real date is 01/12/2010 or on Portuguese 12/01/2010 and use the routine/command convert -> wxString mydata = data.Format(wxT("%x")); date is variable that get the field date(in .mdb) by way of the table->SetColDefs(3, wxT("data"), DB_DATA_TYPE_DATE, &data,
SQL_C_DATE, sizeof(data), false, false);, here my question, como pass,jump date in the .mdb -> wxODBC -> wxTextCtrl? With wxDateTime ? how obtain date 12/01/2010 ?, so, I add, table->SetWhereClause(wxT("#data=01/12/2010#")); is working, is the sucessful, is wondeful, I see that I am near of the sucessful, how convert data of .mdb->wxODBC->wxTextCtrl?, add, below routine event button1:
//---------------------------------------------------------------------------
//
// Name: wxodbc4.cpp
// Author: Marcelo Paiva
// Created: 11/1/2010 22:35:34
// Description: wxodbc4 class implementation
//
//---------------------------------------------------------------------------

#include "wxodbc4.h"
#include "wxodbc2.h"
#include "wx/log.h" // #included to enable output of messages only
#include "wx/dbtable.h"
#include <wx/datetime.h>


//Do not add custom headers between
//Header Include Start and Header Include End
//wxDev-C++ designer will remove them
////Header Include Start
////Header Include End

//----------------------------------------------------------------------------
// wxodbc4
//----------------------------------------------------------------------------
//Add Custom Events only in the appropriate block.
//Code added in other places will be removed by wxDev-C++
////Event Table Start
BEGIN_EVENT_TABLE(wxodbc4,wxFrame)
////Manual Code Start
////Manual Code End

EVT_CLOSE(wxodbc4::OnClose)
EVT_BUTTON(ID_WXBUTTON2,wxodbc4::WxButton2Click)
EVT_BUTTON(ID_WXBUTTON1,wxodbc4::WxButton1Click)
END_EVENT_TABLE()
////Event Table End

wxodbc4::wxodbc4(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style)
: wxFrame(parent, id, title, position, size, style)
{
CreateGUIControls();
}

wxodbc4::~wxodbc4()
{
}

void wxodbc4::CreateGUIControls()
{
//Do not add custom code between
//GUI Items Creation Start and GUI Items Creation End
//wxDev-C++ designer will remove them.
//Add the custom code before or after the blocks
////GUI Items Creation Start

WxPanel1 = new wxPanel(this, ID_WXPANEL1, wxPoint(0,0), wxSize(681,561));
WxPanel1->SetFont(wxFont(9, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Segoe UI")));

WxButton1 = new wxButton(WxPanel1, ID_WXBUTTON1, wxT("Sair"), wxPoint(22,20), wxSize(117,28), 0, wxDefaultValidator, wxT("WxButton1"));
WxButton1->SetFont(wxFont(9, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Segoe UI")));

WxButton2 = new wxButton(WxPanel1, ID_WXBUTTON2, wxT("select"), wxPoint(23,69), wxSize(118,59), 0, wxDefaultValidator, wxT("WxButton2"));
WxButton2->SetFont(wxFont(9, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Segoe UI")));

WxMemo1 = new wxTextCtrl(WxPanel1, ID_WXMEMO1, wxT(""), wxPoint(157,20), wxSize(504,196), wxTE_MULTILINE, wxDefaultValidator, wxT("WxMemo1"));
WxMemo1->SetMaxLength(0);
WxMemo1->AppendText(wxT("WxMemo1"));
WxMemo1->SetFocus();
WxMemo1->SetInsertionPointEnd();
WxMemo1->SetFont(wxFont(9, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Segoe UI")));

SetTitle(wxT("wxodbc4"));
SetIcon(wxNullIcon);
SetSize(8,8,697,597);
Center();

////GUI Items Creation End
}

void wxodbc4::OnClose(wxCloseEvent& event)
{
Destroy();
}

/*
* WxButton1Click
*/
void wxodbc4::WxButton1Click(wxCommandEvent& event)
{
// insert your code here
Destroy();
}

/*
* WxButton2Click
*/
void wxodbc4::WxButton2Click(wxCommandEvent& event)
{
// insert your code here
// insert your code here

// ----------------------------------------------------------------------------
// HEADERS
// ----------------------------------------------------------------------------
//#include "wx/log.h" // #included to enable output of messages only
//#include "wx/dbtable.h"

// ----------------------------------------------------------------------------
// FUNCTION USED FOR HANDLING/DISPLAYING ERRORS
// ----------------------------------------------------------------------------
// Very generic error handling function.
// If a connection to the database is passed in, then we retrieve all the
// database errors for the connection and add them to the displayed message
//int HandleError(wxString errmsg, wxDb *pDb=NULL)
//{
// Retrieve all the error message for the errors that occurred
// wxString allErrors;
// if (!pDb == NULL)
// Get the database errors and append them to the error message
// allErrors = wxDbLogExtendedErrorMsg(errmsg.c_str(), pDb, 0, 0);
// else
// allErrors = errmsg;

// Do whatever you wish with the error message here
// wxLogDebug() is called inside wxDbLogExtendedErrorMsg() so this
// console program will show the errors in the console window,
// but these lines will show the errors in RELEASE builds also
// wxFprintf(stderr, wxT("\n%s\n"), allErrors.c_str());
// fflush(stderr);

// return 1;
//}


// ----------------------------------------------------------------------------
// entry point
// ----------------------------------------------------------------------------
//int main(int argc, char **argv)
//{
wxDbConnectInf *DbConnectInf = NULL; // DB connection information

wxDb *db = NULL; // Database connection

wxDbTable *table = NULL; // Data table to access
const wxChar tableName[] = wxT("twxmdb3"); // Name of database table
const UWORD numTableColumns = 5; // Number table columns
int cod;
wxChar nome[50+1]; // column data: "FIRST_NAME"
int idade;
int int_var;

wxString mycod;
wxString myidade;
wxString mydata;
wxString myhora;
wxDateTime data;
wxDateTime hora;


wxString msg; // Used for display messages

// -----------------------------------------------------------------------
// DEFINE THE CONNECTION HANDLE FOR THE DATABASE
// -----------------------------------------------------------------------
DbConnectInf = new wxDbConnectInf(NULL,wxT("wxmdb12"),wxT(""),wxT(""));

// Error checking....
if (!DbConnectInf || !DbConnectInf->GetHenv())
{
// return HandleError(wxT("DB ENV ERROR: Cannot allocate ODBC env handle"));
WxMemo1->AppendText("DB ENV ERROR: Cannot allocate ODBC env handle");
}


// -----------------------------------------------------------------------
// GET A DATABASE CONNECTION
// -----------------------------------------------------------------------
db = wxDbGetConnection(DbConnectInf);

if (!db)
{
// return HandleError(wxT("CONNECTION ERROR - Cannot get DB connection"));
WxMemo1->AppendText("CONNECTION ERROR - Cannot get DB connection");
}


// -----------------------------------------------------------------------
// DEFINE THE TABLE, AND THE COLUMNS THAT WILL BE ACCESSED
// -----------------------------------------------------------------------
table = new wxDbTable(db, tableName, numTableColumns, wxT(""),!wxDB_QUERY_ONLY, wxT(""));



// Bind the columns that you wish to retrieve. Note that there must be
// 'numTableColumns' calls to SetColDefs(), to match the wxDbTable def
//
// Not all columns need to be bound, only columns whose values are to be
// returned back to the client.
//
table->SetColDefs(0, wxT("cod"), DB_DATA_TYPE_INTEGER,&cod ,
SQL_C_LONG, sizeof(int_var), true,true);
table->SetColDefs(1, wxT("nome"), DB_DATA_TYPE_VARCHAR, nome,
SQL_C_WXCHAR, sizeof(nome), true, true);
table->SetColDefs(2, wxT("idade"), DB_DATA_TYPE_INTEGER, &idade,
SQL_C_LONG, sizeof(int_var), true, true);
table->SetColDefs(3, wxT("data"), DB_DATA_TYPE_DATE, &data,
SQL_C_DATE, sizeof(data), false, false);
table->SetColDefs(4, wxT("hora"), DB_DATA_TYPE_DATE, &hora,
SQL_C_TIMESTAMP, sizeof(hora), false, false);



// -----------------------------------------------------------------------
// CREATE (or RECREATE) THE TABLE IN THE DATABASE
// -----------------------------------------------------------------------
//if (!table->CreateTable(true)) //NOTE: No CommitTrans is required
//{
// return HandleError(wxT("TABLE CREATION ERROR: "), table->GetDb());
// WxMemo1->AppendText("TABLE CREATION ERROR: ");
//}


// -----------------------------------------------------------------------
// OPEN THE TABLE FOR ACCESS
// -----------------------------------------------------------------------
if (!table->Open()){
//return HandleError(wxT("TABLE OPEN ERROR: "), table->GetDb());
WxMemo1->AppendText("TABLE OPEN ERROR: ");
// WxMemo1->AppendText(table->GetDb());
}


// -----------------------------------------------------------------------
// INSERT A NEW ROW INTO THE TABLE
// -----------------------------------------------------------------------
//wxStrcpy(FirstName, wxT("JULIAN"));
//wxStrcpy(LastName, wxT("SMART"));
//if (!table->Insert())
//{
// return HandleError(wxT("INSERTION ERROR: "), table->GetDb());
// WxMemo1->AppendText("INSERTION ERROR: ");
//
//}

// Must commit the insert to write the data to the DB
table->GetDb()->CommitTrans();



// -----------------------------------------------------------------------
// RETRIEVE ROWS FROM THE TABLE BASED ON SUPPLIED CRITERIA
// -----------------------------------------------------------------------
// Set the WHERE clause to limit the result set to return
// all rows that have a value of 'JULIAN' in the FIRST_NAME
// column of the table.


//table->SetWhereClause(wxT("FIRST_NAME = 'JULIAN'"));
table->SetWhereClause(wxT(""));

// Result set will be sorted in ascending alphabetical
// order on the data in the 'LAST_NAME' column of each row
table->SetOrderByClause(wxT("cod"));

// No other tables (joins) are used for this query
table->SetFromClause(wxT(""));


// Instruct the datasource to perform a query based on the
// criteria specified above in the where/orderBy/from clauses.
if (!table->Query())
{
// return HandleError(wxT("QUERY ERROR: "), table->GetDb());
WxMemo1->AppendText("QUERY ERROR: ");
// WxMemo1->AppendText(table->GetDb());
}









//mycod<<cod;
//myidade<<idade;

// Loop through all rows matching the query criteria until
// there are no more records to read


//wxString mynewstring = wxString::Format(_T("%d"), cod);
//wxString s; s.Printf(_T("%d"), cod);



while (table->GetNext())
{

// wxDateTime now = wxDateTime::

// wxString date1 = now.Format();
// wxString date2 = now.Format(wxT("%X"));
// wxString date3 = now.Format(wxT("%x"));




mycod<<cod;
myidade<<idade;


wxString mydata = data.Format(wxT("%x"));
wxString myhora = data.Format(wxT("%X"));






WxMemo1->WriteText("\n");
WxMemo1->WriteText(mycod);
WxMemo1->WriteText(" ");
WxMemo1->WriteText(nome);
WxMemo1->WriteText(" ");
WxMemo1->WriteText(myidade);
WxMemo1->WriteText(" ");
WxMemo1->WriteText(wxT(mydata));
WxMemo1->WriteText(" ");
WxMemo1->WriteText(myhora);
WxMemo1->WriteText(" ");

mycod="";
myidade="";
mydata="";
myhora="";





}

//while (table->GetNext())
//{

// mycod<<cod;
//myidade<<idade;


//wxrtext1->AppendText("\n");
//wxrtext1->AppendText(mycod);
//wxrtext1->AppendText(" ");
//wxrtext1->AppendText(nome);
//wxrtext1->AppendText(" ");
//wxrtext1->AppendText(myidade);
//wxrtext1->AppendText(" ");


//mycod="";
//myidade="";


//}


// -----------------------------------------------------------------------
// DELETE A ROW FROM THE TABLE
// -----------------------------------------------------------------------
// Select the row which has FIRST_NAME of 'JULIAN' and LAST_NAME
// of 'SMART', then delete the retrieved row
//
//if (!table->DeleteWhere(wxT("FIRST_NAME = 'JULIAN' and LAST_NAME = 'SMART'")))
//{
// return HandleError(wxT("DELETION ERROR: "), table->GetDb());
//}

// Must commit the deletion to the database
table->GetDb()->CommitTrans();


// -----------------------------------------------------------------------
// TAKE CARE OF THE ODBC CLASS INSTANCES THAT WERE BEING USED
// -----------------------------------------------------------------------
// If the wxDbTable instance was successfully created
// then delete it as we are done with it now.
wxDELETE(table);

// Free the cached connection
// (meaning release it back in to the cache of datasource
// connections) for the next time a call to wxDbGetConnection()
// is made.
wxDbFreeConnection(db);
db = NULL;


// -----------------------------------------------------------------------
// CLEANUP BEFORE EXITING APP
// -----------------------------------------------------------------------
// The program is now ending, so we need to close
// any cached connections that are still being
// maintained.
wxDbCloseConnections();

// Release the environment handle that was created
// for use with the ODBC datasource connections
wxDELETE(DbConnectInf);

//wxUnusedVar(argc); // Here just to prevent compiler warnings
//wxUnusedVar(argv); // Here just to prevent compiler warnings

//return 0;
}



//}
//}

and saidas wxTextCtrl:
WxMemo1
4 TENTAR 2 08/20/71 09:34:35
false,correct is 01/12/10 or 01/12/2010
and now compile wxDevC++ with MINGW:
WxMemo1
1 marcelo 38 07/01/71 16:31:47
2 pedro 20 07/01/71 16:31:47
3 tentando 10 07/01/71 16:31:47
4 TENTAR 2 08/20/71 09:34:35
5 eee 3 10/09/71 02:37:22
Here my question,
Thank You,
Help me,
Marcelo Paiva, Quilombo SC state, Brazil coutry.
so, routine is a adapted of the wxODBC Sample Code.
I am Marcelo Paiva, I live in Quilombo town, Santa Catarina State, Brazil Country.

Marcelo Paiva
In need of some credit
In need of some credit
Posts: 3
Joined: Thu Jan 14, 2010 1:49 pm
Location: Rua Guido Both s/n Quilombo/SC Brasil CEP89850000
Contact:

Postby Marcelo Paiva » Thu Jan 14, 2010 6:17 pm

Sorry, on the strat my post been strang, Sorry I beginner.

Marcelo Paiva
I am Marcelo Paiva, I live in Quilombo town, Santa Catarina State, Brazil Country.

Marcelo Paiva
In need of some credit
In need of some credit
Posts: 3
Joined: Thu Jan 14, 2010 1:49 pm
Location: Rua Guido Both s/n Quilombo/SC Brasil CEP89850000
Contact:

The question, the problem resolved

Postby Marcelo Paiva » Mon Jan 18, 2010 10:57 am

Hallo,
I post here to inform I resolved my question with succesfull.
So, to print date in WxMemo I define:
1)Variable will be used how type wxDateTime, and add...
2)table->SetColDef with:table->SetColDefs(3, wxT("data"), DB_DATA_TYPE_DATE, &data,
SQL_C_DATE, sizeof(data), true, true);

table->SetColDefs(4, wxT("hora"), DB_DATA_TYPE_DATE, &hora,
SQL_C_TIME, sizeof(hora), true, true);
3)add, more, I set WxMemo1->WriteText with (table->GetColumn(0)); so, I obtain sucessfull to set wxString of the WxMemo1 with double,long.date of the "sqlquery", so, I make how down:
WxMemo1->WriteText("\n");
WxMemo1->WriteText(table->GetColumn(0));
WxMemo1->WriteText(" ");
WxMemo1->WriteText(table->GetColumn(1));
WxMemo1->WriteText(" ");
WxMemo1->WriteText(table->GetColumn(2));
WxMemo1->WriteText(" ");
//WxMemo1->WriteText(table->GetColumn(3));
WxMemo1->WriteText(mydata);
WxMemo1->WriteText(" ");
//WxMemo1->WriteText(table->GetColumn(4));
WxMemo1->WriteText(myhora);
WxMemo1->WriteText(" ");
, more ... :
to date and time, I need to work GetColumn by intermediate variables with the objetive of the format date and time to the format "%d/%m/%y" and time "%X", so, see below:
wxDateTime data1=table->GetColumn(3);
wxString mydata=data1.Format(wxT("%d/%m/%y"));

wxDateTime hora1=table->GetColumn(4);
wxString myhora=hora1.Format(wxT("%X"));



WxMemo1->WriteText("\n");
WxMemo1->WriteText(table->GetColumn(0));
WxMemo1->WriteText(" ");
WxMemo1->WriteText(table->GetColumn(1));
WxMemo1->WriteText(" ");
WxMemo1->WriteText(table->GetColumn(2));
WxMemo1->WriteText(" ");
//WxMemo1->WriteText(table->GetColumn(3));
WxMemo1->WriteText(mydata);
WxMemo1->WriteText(" ");
//WxMemo1->WriteText(table->GetColumn(4));
WxMemo1->WriteText(myhora);
WxMemo1->WriteText(" ");

, and, at the all cod in button below:

--------------------------------------------------------------
//
// Name: wxodbc4.cpp
// Author: Marcelo Paiva
// Created: 11/1/2010 22:35:34
// Description: wxodbc4 class implementation
//
//---------------------------------------------------------------------------

#include "wxodbc4.h"
#include "wxodbc2.h"
#include "wx/log.h" // #included to enable output of messages only
#include "wx/dbtable.h"
#include <wx/datetime.h>


//Do not add custom headers between
//Header Include Start and Header Include End
//wxDev-C++ designer will remove them
////Header Include Start
////Header Include End

//----------------------------------------------------------------------------
// wxodbc4
//----------------------------------------------------------------------------
//Add Custom Events only in the appropriate block.
//Code added in other places will be removed by wxDev-C++
////Event Table Start
BEGIN_EVENT_TABLE(wxodbc4,wxFrame)
////Manual Code Start
////Manual Code End

EVT_CLOSE(wxodbc4::OnClose)
EVT_BUTTON(ID_WXBUTTON2,wxodbc4::WxButton2Click)
EVT_BUTTON(ID_WXBUTTON1,wxodbc4::WxButton1Click)
END_EVENT_TABLE()
////Event Table End

wxodbc4::wxodbc4(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style)
: wxFrame(parent, id, title, position, size, style)
{
CreateGUIControls();
}

wxodbc4::~wxodbc4()
{
}

void wxodbc4::CreateGUIControls()
{
//Do not add custom code between
//GUI Items Creation Start and GUI Items Creation End
//wxDev-C++ designer will remove them.
//Add the custom code before or after the blocks
////GUI Items Creation Start

WxPanel1 = new wxPanel(this, ID_WXPANEL1, wxPoint(0,0), wxSize(681,561));
WxPanel1->SetFont(wxFont(9, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Segoe UI")));

WxButton1 = new wxButton(WxPanel1, ID_WXBUTTON1, wxT("Sair"), wxPoint(22,20), wxSize(117,28), 0, wxDefaultValidator, wxT("WxButton1"));
WxButton1->SetFont(wxFont(9, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Segoe UI")));

WxButton2 = new wxButton(WxPanel1, ID_WXBUTTON2, wxT("select"), wxPoint(23,69), wxSize(118,59), 0, wxDefaultValidator, wxT("WxButton2"));
WxButton2->SetFont(wxFont(9, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Segoe UI")));

WxMemo1 = new wxTextCtrl(WxPanel1, ID_WXMEMO1, wxT(""), wxPoint(157,20), wxSize(504,196), wxTE_MULTILINE, wxDefaultValidator, wxT("WxMemo1"));
WxMemo1->SetMaxLength(0);
WxMemo1->AppendText(wxT("WxMemo1"));
WxMemo1->SetFocus();
WxMemo1->SetInsertionPointEnd();
WxMemo1->SetFont(wxFont(9, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Segoe UI")));

SetTitle(wxT("wxodbc4"));
SetIcon(wxNullIcon);
SetSize(8,8,697,597);
Center();

////GUI Items Creation End
}

void wxodbc4::OnClose(wxCloseEvent& event)
{
Destroy();
}

/*
* WxButton1Click
*/
void wxodbc4::WxButton1Click(wxCommandEvent& event)
{
// insert your code here
Destroy();
}

/*
* WxButton2Click
*/
void wxodbc4::WxButton2Click(wxCommandEvent& event)
{
// insert your code here
// insert your code here

// ----------------------------------------------------------------------------
// HEADERS
// ----------------------------------------------------------------------------
//#include "wx/log.h" // #included to enable output of messages only
//#include "wx/dbtable.h"

// ----------------------------------------------------------------------------
// FUNCTION USED FOR HANDLING/DISPLAYING ERRORS
// ----------------------------------------------------------------------------
// Very generic error handling function.
// If a connection to the database is passed in, then we retrieve all the
// database errors for the connection and add them to the displayed message
//int HandleError(wxString errmsg, wxDb *pDb=NULL)
//{
// Retrieve all the error message for the errors that occurred
// wxString allErrors;
// if (!pDb == NULL)
// Get the database errors and append them to the error message
// allErrors = wxDbLogExtendedErrorMsg(errmsg.c_str(), pDb, 0, 0);
// else
// allErrors = errmsg;

// Do whatever you wish with the error message here
// wxLogDebug() is called inside wxDbLogExtendedErrorMsg() so this
// console program will show the errors in the console window,
// but these lines will show the errors in RELEASE builds also
// wxFprintf(stderr, wxT("\n%s\n"), allErrors.c_str());
// fflush(stderr);

// return 1;
//}


// ----------------------------------------------------------------------------
// entry point
// ----------------------------------------------------------------------------
//int main(int argc, char **argv)
//{
wxDbConnectInf *DbConnectInf = NULL; // DB connection information

wxDb *db = NULL; // Database connection

wxDbTable *table = NULL; // Data table to access
const wxChar tableName[] = wxT("twxmdb3"); // Name of database table
const UWORD numTableColumns = 5; // Number table columns
int cod;
wxChar nome[50+1]; // column data: "FIRST_NAME"
int idade;
int int_var;

wxString mycod;
wxString myidade;
wxString mydata;
wxString myhora;
wxDateTime data;
wxDateTime hora;


wxString msg; // Used for display messages

// -----------------------------------------------------------------------
// DEFINE THE CONNECTION HANDLE FOR THE DATABASE
// -----------------------------------------------------------------------
DbConnectInf = new wxDbConnectInf(NULL,wxT("wxmdb12"),wxT(""),wxT(""));

// Error checking....
if (!DbConnectInf || !DbConnectInf->GetHenv())
{
// return HandleError(wxT("DB ENV ERROR: Cannot allocate ODBC env handle"));
WxMemo1->AppendText("DB ENV ERROR: Cannot allocate ODBC env handle");
}


// -----------------------------------------------------------------------
// GET A DATABASE CONNECTION
// -----------------------------------------------------------------------
db = wxDbGetConnection(DbConnectInf);

if (!db)
{
// return HandleError(wxT("CONNECTION ERROR - Cannot get DB connection"));
WxMemo1->AppendText("CONNECTION ERROR - Cannot get DB connection");
}


// -----------------------------------------------------------------------
// DEFINE THE TABLE, AND THE COLUMNS THAT WILL BE ACCESSED
// -----------------------------------------------------------------------
table = new wxDbTable(db, tableName, numTableColumns, wxT(""),!wxDB_QUERY_ONLY, wxT(""));



// Bind the columns that you wish to retrieve. Note that there must be
// 'numTableColumns' calls to SetColDefs(), to match the wxDbTable def
//
// Not all columns need to be bound, only columns whose values are to be
// returned back to the client.
//
table->SetColDefs(0, wxT("cod"), DB_DATA_TYPE_INTEGER,&cod ,
SQL_C_LONG, sizeof(int_var), true,true);
table->SetColDefs(1, wxT("nome"), DB_DATA_TYPE_VARCHAR, nome,
SQL_C_WXCHAR, sizeof(nome), true, true);
table->SetColDefs(2, wxT("idade"), DB_DATA_TYPE_INTEGER, &idade,
SQL_C_LONG, sizeof(int_var), true, true);
table->SetColDefs(3, wxT("data"), DB_DATA_TYPE_DATE, &data,
SQL_C_DATE, sizeof(data), true, true);

table->SetColDefs(4, wxT("hora"), DB_DATA_TYPE_DATE, &hora,
SQL_C_TIME, sizeof(hora), true, true);



// -----------------------------------------------------------------------
// CREATE (or RECREATE) THE TABLE IN THE DATABASE
// -----------------------------------------------------------------------
//if (!table->CreateTable(true)) //NOTE: No CommitTrans is required
//{
// return HandleError(wxT("TABLE CREATION ERROR: "), table->GetDb());
// WxMemo1->AppendText("TABLE CREATION ERROR: ");
//}


// -----------------------------------------------------------------------
// OPEN THE TABLE FOR ACCESS
// -----------------------------------------------------------------------
if (!table->Open()){
//return HandleError(wxT("TABLE OPEN ERROR: "), table->GetDb());
WxMemo1->AppendText("TABLE OPEN ERROR: ");
// WxMemo1->AppendText(table->GetDb());
}


// -----------------------------------------------------------------------
// INSERT A NEW ROW INTO THE TABLE
// -----------------------------------------------------------------------
//wxStrcpy(FirstName, wxT("JULIAN"));
//wxStrcpy(LastName, wxT("SMART"));
//if (!table->Insert())
//{
// return HandleError(wxT("INSERTION ERROR: "), table->GetDb());
// WxMemo1->AppendText("INSERTION ERROR: ");
//
//}

// Must commit the insert to write the data to the DB
table->GetDb()->CommitTrans();



// -----------------------------------------------------------------------
// RETRIEVE ROWS FROM THE TABLE BASED ON SUPPLIED CRITERIA
// -----------------------------------------------------------------------
// Set the WHERE clause to limit the result set to return
// all rows that have a value of 'JULIAN' in the FIRST_NAME
// column of the table.


//table->SetWhereClause(wxT("FIRST_NAME = 'JULIAN'"));
table->SetWhereClause(wxT(""));

// Result set will be sorted in ascending alphabetical
// order on the data in the 'LAST_NAME' column of each row
table->SetOrderByClause(wxT("cod"));

// No other tables (joins) are used for this query
table->SetFromClause(wxT(""));


// Instruct the datasource to perform a query based on the
// criteria specified above in the where/orderBy/from clauses.
if (!table->Query())
{
// return HandleError(wxT("QUERY ERROR: "), table->GetDb());
WxMemo1->AppendText("QUERY ERROR: ");
// WxMemo1->AppendText(table->GetDb());
}









//mycod<<cod;
//myidade<<idade;

// Loop through all rows matching the query criteria until
// there are no more records to read


//wxString mynewstring = wxString::Format(_T("%d"), cod);
//wxString s; s.Printf(_T("%d"), cod);



while (table->GetNext())
{

// wxDateTime now = wxDateTime::

// wxString date1 = now.Format();
// wxString date2 = now.Format(wxT("%X"));
// wxString date3 = now.Format(wxT("%x"));




//mycod<<cod;
//myidade<<idade;
//mydata<<data;
//myhora<<hora;

//wxString mydata = data.Format(wxT("%x"));
//wxString myhora = data.Format(wxT("%X"));

wxDateTime data1=table->GetColumn(3);
wxString mydata=data1.Format(wxT("%d/%m/%y"));

wxDateTime hora1=table->GetColumn(4);
wxString myhora=hora1.Format(wxT("%X"));



WxMemo1->WriteText("\n");
WxMemo1->WriteText(table->GetColumn(0));
WxMemo1->WriteText(" ");
WxMemo1->WriteText(table->GetColumn(1));
WxMemo1->WriteText(" ");
WxMemo1->WriteText(table->GetColumn(2));
WxMemo1->WriteText(" ");
//WxMemo1->WriteText(table->GetColumn(3));
WxMemo1->WriteText(mydata);
WxMemo1->WriteText(" ");
//WxMemo1->WriteText(table->GetColumn(4));
WxMemo1->WriteText(myhora);
WxMemo1->WriteText(" ");

//mycod=""; to make cod to clean WxMemo1->Strings
//myidade="";
//mydata="";
//myhora="";





}

//while (table->GetNext())
//{

// mycod<<cod;
//myidade<<idade;


//wxrtext1->AppendText("\n");
//wxrtext1->AppendText(mycod);
//wxrtext1->AppendText(" ");
//wxrtext1->AppendText(nome);
//wxrtext1->AppendText(" ");
//wxrtext1->AppendText(myidade);
//wxrtext1->AppendText(" ");


//mycod="";
//myidade="";


//}


// -----------------------------------------------------------------------
// DELETE A ROW FROM THE TABLE
// -----------------------------------------------------------------------
// Select the row which has FIRST_NAME of 'JULIAN' and LAST_NAME
// of 'SMART', then delete the retrieved row
//
//if (!table->DeleteWhere(wxT("FIRST_NAME = 'JULIAN' and LAST_NAME = 'SMART'")))
//{
// return HandleError(wxT("DELETION ERROR: "), table->GetDb());
//}

// Must commit the deletion to the database
table->GetDb()->CommitTrans();


// -----------------------------------------------------------------------
// TAKE CARE OF THE ODBC CLASS INSTANCES THAT WERE BEING USED
// -----------------------------------------------------------------------
// If the wxDbTable instance was successfully created
// then delete it as we are done with it now.
wxDELETE(table);

// Free the cached connection
// (meaning release it back in to the cache of datasource
// connections) for the next time a call to wxDbGetConnection()
// is made.
wxDbFreeConnection(db);
db = NULL;


// -----------------------------------------------------------------------
// CLEANUP BEFORE EXITING APP
// -----------------------------------------------------------------------
// The program is now ending, so we need to close
// any cached connections that are still being
// maintained.
wxDbCloseConnections();

// Release the environment handle that was created
// for use with the ODBC datasource connections
wxDELETE(DbConnectInf);

//wxUnusedVar(argc); // Here just to prevent compiler warnings
//wxUnusedVar(argv); // Here just to prevent compiler warnings

//return 0;
}



//}
//}

observ: the cod is crude form,

Thank you,

Thank you, by opportunity.

Marcelo Paiva
I am Marcelo Paiva, I live in Quilombo town, Santa Catarina State, Brazil Country.


Return to “wxCode”

Who is online

Users browsing this forum: No registered users and 1 guest