Click to See Complete Forum and Search --> : MySQL Connectivity
sharanu
April 14th, 2003, 01:33 AM
Hai friends,
I have installed MySQL server 4.0.12 to my system on linux platform. We are using C program to connect to the MySQL database. Can the C code be implemented from C++ without and problems ?
If yes do we have to make some changes ?
Please reply me.
j_sakthivel
May 21st, 2003, 07:57 AM
goto www.mysql.com site.
hope u understand
anji_m8
May 30th, 2005, 10:38 PM
Hai friends,
I have installed MySQL server 4.0.12 to my system on linux platform. We are using C program to connect to the MySQL database. Can the C code be implemented from C++ without and problems ?
If yes do we have to make some changes ?
Please reply me.
OleInitialize( NULL );
OleUninitialize();
IDBInitialize* pIDBInitialize = NULL;
IDBCreateCommand* pIDBCreateCommand = NULL;
ICommand* pICommand = NULL;
ICommandText* pICommandText = NULL;
IDBInitialize* pIDBInit = NULL;
IDBProperties* pIDBProperties = NULL;
DBPROPSET dbPropSet[1];
DBPROP dbProp[1];
hr = CoCreateInstance( CLSID_MySqlProv,
NULL,
CLSCTX_INPROC_SERVER,
IID_IDBInitialize,
(void **)&pIDBInit );
VariantInit(&(dbProp[0].vValue));
dbPropSet[0].rgProperties = &dbProp[0];
dbPropSet[0].cProperties = 1;
dbPropSet[0].guidPropertySet = DBPROPSET_DBINIT;
dbProp[0].dwPropertyID = DBPROP_INIT_DATASOURCE;
dbProp[0].dwOptions = DBPROPOPTIONS_REQUIRED;
dbProp[0].colid = DB_NULLID;
V_VT(&(dbProp[0].vValue)) = VT_BSTR;
V_BSTR(&(dbProp[0].vValue)) = SysAllocString( DEF_MYSQL_CONN );
hr = pIDBInit->QueryInterface( IID_IDBProperties, (void**)&pIDBProperties);
hr = pIDBInit->Initialize();
*ppIDBInitialize_out = pIDBInit;
IDBCreateSession* pIDBCreateSession;
IDBCreateCommand* pIDBCreateCommand;
hr = pIDBInitialize->QueryInterface( IID_IDBCreateSession, (void**)&pIDBCreateSession);
hr = pIDBCreateSession->CreateSession( NULL, IID_IDBCreateCommand, (IUnknown**)&pIDBCreateCommand );
*ppIDBCreateCommand_out = pIDBCreateCommand;
ICommand* pICommand = NULL;
hr = pIDBCreateCommand->CreateCommand (NULL, // pUnkOuter - we are not aggregating
IID_ICommand, // riid - interface we want on the command object
(IUnknown**)&pICommand ); // ppCommand
*ppICommand_out = pICommand;
#include <windows.h> //
#include <ole2ver.h> // OLE2.0 build version
#include <cguid.h> // GUID_NULL
#include <stdio.h> // vsnprintf, etc.
#include <stddef.h> // offsetof
#include <stdarg.h> // va_arg
#include <time.h> // time
#include <assert.h> // assert
#include <conio.h> // _getch()
// OLE DB headers
#include <oledb.h>
#include <oledberr.h>
// -----------------------------------------
// Queries
// -----------------------------------------
#define TEST_TABLE "Extra7"
#define LTEST_TABLE L"Extra7"
#define CREATE_TABLE_QUERY L"CREATE TABLE " LTEST_TABLE L" (a SMALLINT, b VARCHAR(20))"
#define INSERT_ROW_QUERY L"INSERT INTO " LTEST_TABLE L" VALUES (777, 'Good number')"
#define DROP_TABLE_QUERY L"DROP TABLE " LTEST_TABLE
one step to run commenad
hr = pICommandText->SetCommandText( DBGUID_DBSQL, CREATE_TABLE_QUERY );
if (FAILED(hr))
{
DUMP_ERROR_LINENUMBER();
DumpErrorHResult( hr, "SetCommandText");
goto error;
}
hr = pICommand->Execute( NULL, IID_IRowset, NULL, &cRowsAffected, (IUnknown**)&pIRowset );
pICommandText->Release();
pICommandText = NULL;
pICommand->Release();
pICommand = NULL;
CoFreeUnusedLibraries();
OLE DB Provider for MySQL (By Todd Smith)
strConnection = _T("Provider=MySQLProv;Data Source=test");
Where test is the name of MySQL database. Also, you can replace the name of the database by the following connection string: server=localhost;DB=test.
anji_m8
June 20th, 2005, 10:37 PM
see example in windows NT and vc++ 6.0 In Linux there is no com and dll so sorry....
OleInitialize( NULL );
OleUninitialize();
IDBInitialize* pIDBInitialize = NULL;
IDBCreateCommand* pIDBCreateCommand = NULL;
ICommand* pICommand = NULL;
ICommandText* pICommandText = NULL;
IDBInitialize* pIDBInit = NULL;
IDBProperties* pIDBProperties = NULL;
DBPROPSET dbPropSet[1];
DBPROP dbProp[1];
hr = CoCreateInstance( CLSID_MySqlProv,
NULL,
CLSCTX_INPROC_SERVER,
IID_IDBInitialize,
(void **)&pIDBInit );
VariantInit(&(dbProp[0].vValue));
dbPropSet[0].rgProperties = &dbProp[0];
dbPropSet[0].cProperties = 1;
dbPropSet[0].guidPropertySet = DBPROPSET_DBINIT;
dbProp[0].dwPropertyID = DBPROP_INIT_DATASOURCE;
dbProp[0].dwOptions = DBPROPOPTIONS_REQUIRED;
dbProp[0].colid = DB_NULLID;
V_VT(&(dbProp[0].vValue)) = VT_BSTR;
V_BSTR(&(dbProp[0].vValue)) = SysAllocString( DEF_MYSQL_CONN );
hr = pIDBInit->QueryInterface( IID_IDBProperties, (void**)&pIDBProperties);
hr = pIDBInit->Initialize();
*ppIDBInitialize_out = pIDBInit;
IDBCreateSession* pIDBCreateSession;
IDBCreateCommand* pIDBCreateCommand;
hr = pIDBInitialize->QueryInterface( IID_IDBCreateSession, (void**)&pIDBCreateSession);
hr = pIDBCreateSession->CreateSession( NULL, IID_IDBCreateCommand, (IUnknown**)&pIDBCreateCommand );
*ppIDBCreateCommand_out = pIDBCreateCommand;
ICommand* pICommand = NULL;
hr = pIDBCreateCommand->CreateCommand (NULL, // pUnkOuter - we are not aggregating
IID_ICommand, // riid - interface we want on the command object
(IUnknown**)&pICommand ); // ppCommand
*ppICommand_out = pICommand;
#include <windows.h> //
#include <ole2ver.h> // OLE2.0 build version
#include <cguid.h> // GUID_NULL
#include <stdio.h> // vsnprintf, etc.
#include <stddef.h> // offsetof
#include <stdarg.h> // va_arg
#include <time.h> // time
#include <assert.h> // assert
#include <conio.h> // _getch()
// OLE DB headers
#include <oledb.h>
#include <oledberr.h>
// -----------------------------------------
// Queries
// -----------------------------------------
#define TEST_TABLE "Extra7"
#define LTEST_TABLE L"Extra7"
#define CREATE_TABLE_QUERY L"CREATE TABLE " LTEST_TABLE L" (a SMALLINT, b VARCHAR(20))"
#define INSERT_ROW_QUERY L"INSERT INTO " LTEST_TABLE L" VALUES (777, 'Good number')"
#define DROP_TABLE_QUERY L"DROP TABLE " LTEST_TABLE
one step to run commenad
hr = pICommandText->SetCommandText( DBGUID_DBSQL, CREATE_TABLE_QUERY );
if (FAILED(hr))
{
DUMP_ERROR_LINENUMBER();
DumpErrorHResult( hr, "SetCommandText");
goto error;
}
hr = pICommand->Execute( NULL, IID_IRowset, NULL, &cRowsAffected, (IUnknown**)&pIRowset );
pICommandText->Release();
pICommandText = NULL;
pICommand->Release();
pICommand = NULL;
CoFreeUnusedLibraries();
OLE DB Provider for MySQL (By Todd Smith)
strConnection = _T("Provider=MySQLProv;Data Source=test");
Where test is the name of MySQL database. Also, you can replace the name of the database by the following connection string: server=localhost;DB=test.
hspc
June 21st, 2005, 02:16 AM
Hai friends,
I have installed MySQL server 4.0.12 to my system on linux platform. We are using C program to connect to the MySQL database. Can the C code be implemented from C++ without and problems ?
If yes do we have to make some changes ?
Please reply me.I did not try this with MySQL
but in general I believe you'll be able make the old code work without alot of changes..
Check this FAQ :
http://www.research.att.com/~bs/bs_faq.html#C-is-subset
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.