vlado_036 @ 12.05.2008. 11:30
Moze li neko da mi pomogne i objasni kako da se povezem na MySQL server koristeci Visual C++ 9
Koristim Visual studio 2008, MySQL server 5.0.45, Windows XP SP2
Hvala
itf @ 12.05.2008. 13:11
Jesi možda probao preko ODBC-a?
deerbeer @ 12.05.2008. 14:58
http://www.functionx.com/visualc/databases/sqltable.htm
Primer je doduse za SQL Server al posto se radi o ODBC drajverima sigurno mozes da se nakacis i na MySQL
vlado_036 @ 12.05.2008. 15:05
Primer je OK ali ja bih u aplikaciju koja vec funkcionise hteo da dodam neke dijaloge koji bi prikazivali podatke iz MySQL baze. Problem je sto je aplikacija je bazirana na dialogu i nema ukljucenu podrsku za baze. Probao sam da u projekat ukljucim sve fajlove iz MySQL include direktorijuma i tako da ih koristim ali ne moze, mada bi mi neka slicna tome varijanta najvise odgovarala.
Moze li u ovom slucaju da se koristi ODBC?
Bilo koji nacin koji radi mi odgovara :)
deerbeer @ 12.05.2008. 15:17
Naravno da mozes da koristis ODBC API za konekciju ka MySQL serveru ...
U ODBC32.dll su funkcije koje ti to omogucavaju ...
al je sam pristup i koriscenje API-ija dosta slozeno (low-level C ) pa ti stoga preporucujem da skines neki od free "ODBC wrapera" klasa koje ti pojednostavljuju rad
Na primer : .
http://www.codeguru.com/cpp/da...tabase/odbc/article.php/c4337/
vlado_036 @ 21.05.2008. 10:50
Probao sam nekoliko (vise od 10) ODBC Wrapper-a ali ni jedan nije hteo da se bez greske kompajlira, svaki za sebe prijavljuje druge greske. Svisu pisani za Visual C++ 6 a ja koristim Visual C++ 9, da li je u tome problem?
Uspeo sam preko CDatabase i CRecordset da iscitavam podatke iz MySQL baze.
deerbeer @ 21.05.2008. 11:16
Citat:
vlado_036: Probao sam nekoliko (vise od 10) ODBC Wrapper-a ali ni jedan nije hteo da se bez greske kompajlira, svaki za sebe prijavljuje druge greske. Svisu pisani za Visual C++ 6 a ja koristim Visual C++ 9, da li je u tome problem?
Uspeo sam preko CDatabase i CRecordset da iscitavam podatke iz MySQL baze.
Ajde paste-uj compiler greske da se vidi o cemu se radi ...
Ja sam probao taj ODBC wrapper za koji sam ti dao link u VS2005 (MFC 8.0) i prosao je bez problema ...
Desava se uglavnom da su to sitne ispravke koje treba otkloniti
(drugi header-i ,razliciti deklarisani tipovi ili pointeri na neke funkcije itd ..)
Ako ne uspes da iskompajliras imas u tom direktorijumu gsodbc.lib fajl koji treba da ulinkujes u tvoj program i da onda samo pozivas njegove funkcije
vlado_036 @ 22.05.2008. 07:50
Evo gresaka
stmt.cpp(115) : error C2664: 'SQLExecDirectW' : cannot convert parameter 2 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
stmt.cpp(202) : error C2664: 'SQLPrepareW' : cannot convert parameter 2 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
stmt.cpp(509) : error C2664: 'SQLDescribeColW' : cannot convert parameter 3 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
stmt.cpp(742) : error C2664: 'GetDateFormatW' : cannot convert parameter 5 from 'char [1024]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
stmt.cpp(755) : error C2664: 'GetDateFormatW' : cannot convert parameter 5 from 'char [1024]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
stmt.cpp(759) : error C2664: 'GetTimeFormatW' : cannot convert parameter 5 from 'char *' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
stmt.cpp(879) : error C2664: 'SQLErrorW' : cannot convert parameter 4 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
stmt.cpp(1022) : warning C4018: '<' : signed/unsigned mismatch
stmt.cpp(1039) : warning C4018: '<' : signed/unsigned mismatch
stmt.cpp(1088) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
stmt.cpp(1300) : error C2664: 'SQLNativeSqlW' : cannot convert parameter 2 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Columns.cpp
columns.cpp(68) : error C2664: 'SQLColumnsW' : cannot convert parameter 2 from 'UCHAR *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
columns.cpp(117) : error C2664: 'ATL::CStringT<BaseType,StringTraits>::CStringT(const VARIANT &)' : cannot convert parameter 1 from 'const char [2]' to 'const VARIANT &'
with
[
BaseType=wchar_t,
StringTraits=StrTraitMFC<wchar_t>
]
Reason: cannot convert from 'const char [2]' to 'const VARIANT'
No constructor could take the source type, or constructor overload resolution was ambiguous
connect.cpp
connect.cpp(44) : error C2664: 'SQLConnectW' : cannot convert parameter 2 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
connect.cpp(78) : error C2664: 'SQLDriverConnectW' : cannot convert parameter 3 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
connect.cpp(126) : error C2664: 'SQLErrorW' : cannot convert parameter 4 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
connect.cpp(288) : error C2664: 'SQLTablesW' : cannot convert parameter 6 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
connect.cpp(313) : error C2664: 'SQLColumnsW' : cannot convert parameter 6 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
connect.cpp(339) : error C2664: 'SQLDataSourcesW' : cannot convert parameter 3 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
connect.cpp(352) : error C2664: 'SQLDataSourcesW' : cannot convert parameter 3 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp
cur.cpp(41) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\string.h(74) : see declaration of 'strcpy'
cur.cpp(42) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\string.h(74) : see declaration of 'strcpy'
cur.cpp(43) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\string.h(79) : see declaration of 'strcat'
cur.cpp(49) : error C2664: 'GetTempPathW' : cannot convert parameter 2 from 'char [260]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(50) : error C2664: 'GetTempFileNameW' : cannot convert parameter 1 from 'char [260]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(325) : error C2664: 'GetTempPathW' : cannot convert parameter 2 from 'char [260]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(326) : error C2664: 'GetTempFileNameW' : cannot convert parameter 1 from 'char [260]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(451) : error C2664: 'DeleteFileW' : cannot convert parameter 1 from 'char [260]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(453) : error C2664: 'DeleteFileW' : cannot convert parameter 1 from 'char [260]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(584) : error C2664: 'GetDateFormatW' : cannot convert parameter 5 from 'char [1024]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(597) : error C2664: 'GetDateFormatW' : cannot convert parameter 5 from 'char [1024]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(601) : error C2664: 'GetTimeFormatW' : cannot convert parameter 5 from 'char *' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(772) : warning C4018: '<' : signed/unsigned mismatch
cur.cpp(935) : warning C4018: '<' : signed/unsigned mismatch
cur.cpp(1033) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
curex.cpp
curex.cpp(19) : error C2664: 'LoadStringW' : cannot convert parameter 3 from 'char [256]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
curex.cpp(28) : error C2664: 'LoadStringW' : cannot convert parameter 3 from 'char [256]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
curex.cpp(38) : error C2664: 'LoadStringW' : cannot convert parameter 3 from 'char [256]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
excpt.cpp
excpt.cpp(23) : error C2664: 'LoadStringW' : cannot convert parameter 3 from 'char [256]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
deerbeer @ 22.05.2008. 09:01
Projekat ti je definisan da koristi Unicode charset (tj. WCHAR)..
a wrapper podrzava samo Ansi charset (char* )
Ako ti nije preko potreban Unicode promeni umesto "Use Unicode Charset " u Project Properties u Charset -> Use MultiByte Charset ..
i radice ti ...
Ako ti je bas potreban Unicode u tvom projektu onda je situacija malo teza ...
wrapper klase moras preraditi da koriste Unicode karaktere (promeni sve char* u wchar_t* )
vlado_036 @ 22.05.2008. 11:39
Zamenio sam sve char* u wchar_t*.
Sada imam sledece greske :
Compiling...
Columns.cpp
columns.cpp : error C2471: cannot update program database 'e:\program\vp\vp\debug\vc90.pdb'
columns.cpp : fatal error C1083: Cannot open program database file: 'e:\program\vp\vp\debug\vc90.pdb': No such file or directory
connect.cpp
connect.cpp : error C2471: cannot update program database 'e:\program\vp\vp\debug\vc90.pdb'
connect.cpp : fatal error C1083: Cannot open program database file: 'e:\program\vp\vp\debug\vc90.pdb': No such file or directory
cur.cpp
cur.cpp : error C2471: cannot update program database 'e:\program\vp\vp\debug\vc90.pdb'
cur.cpp : fatal error C1083: Cannot open program database file: 'e:\program\vp\vp\debug\vc90.pdb': No such file or directory
curex.cpp
curex.cpp : error C2471: cannot update program database 'e:\program\vp\vp\debug\vc90.pdb'
curex.cpp : fatal error C1083: Cannot open program database file: 'e:\program\vp\vp\debug\vc90.pdb': No such file or directory
curidx.cpp
curidx.cpp : error C2471: cannot update program database 'e:\program\vp\vp\debug\vc90.pdb'
curidx.cpp : fatal error C1083: Cannot open program database file: 'e:\program\vp\vp\debug\vc90.pdb': No such file or directory
excpt.cpp
excpt.cpp : error C2471: cannot update program database 'e:\program\vp\vp\debug\vc90.pdb'
excpt.cpp : fatal error C1083: Cannot open program database file: 'e:\program\vp\vp\debug\vc90.pdb': No such file or directory
stmt.cpp
stmt.cpp : error C2471: cannot update program database 'e:\program\vp\vp\debug\vc90.pdb'
stmt.cpp : fatal error C1083: Cannot open program database file: 'e:\program\vp\vp\debug\vc90.pdb': No such file or directory
deerbeer @ 22.05.2008. 11:46
Uradi jedan Clean Solution pa Rebuild ..
*.pdb je fajl gde Visual Studio smesta podatke za debug-ovanje
Takodje pogledaj da li jos negde u kodu imas npr :
func("SQL UPIT") -> func(_T("SQL UPIT"));
_T() je makro koji transformise string pod navodnicima u unicode string
[Ovu poruku je menjao deerbeer dana 22.05.2008. u 13:03 GMT+1]
vlado_036 @ 23.05.2008. 11:54
Ponovo sam presao sve fajlove i zamenio char sa wchar_t i sad je OK.
Problem je sad konekcija, ubacio sam makto _T() na svim mestima gde se koriste SQL upiti.
dbCon.connect(_T("MyODBC"), _T("root"), _T("xxx"));
Evo greske koja se javlja kada pokusam da uspostavim konekciju :
error LNK2019: unresolved external symbol "public: void __thiscall CGOdbcConnect::connect(wchar_t const *,wchar_t const *,wchar_t const *)" (?connect@CGOdbcConnect@@QAEXPB_W00@Z) referenced in function "public: void __thiscall CPrijemDlg::OnBnClickedBnSnimi(void)" (?OnBnClickedBnSnimi@CPrijemDlg@@QAEXXZ)
deerbeer @ 23.05.2008. 12:12
Ako si komponentu iskompajlirao kao DLL ili kao static LIB ..
onda je dodaj u Linker Modules njenu putanju ....
Ako si source od komponente ubacio u sam projekat negde
pogledaj da li je source fajl na toj putanj.
Jer ova greska ukazuje na to da imas header-e (zato ti compile prolazi)
a nemas source code u toku linkovanja ....
Copyright (C) 2001-2008 by www.elitesecurity.org. All rights reserved.