|
MySQL Has the following core functions:
connect(), query(), store_result(), fetch_[row, feild]() num_rows(), num fields(),
escape_string(), and close()
There are others, but those are the most used.
Data returned is all characters, and and you get to the data by:
row=fetch_row(query_result);
and row[N] = field N, it's that simple!
Is there anything that simple for ADO or ODBC? I'm trying to port a MySQL app to SQL Server, and having a hard time finding anything that simple. My real concern is handling user-defined queries. In MySQL it was as easy as:
con=connect();
select_database(con, "my database");
query(con, user_sql);
result=store_restult(con);
fields=num_fields(result);
while (row=fetch_row(result)){
for (f=0; f< fields; f++){
printf("%s", row[f]);
}
}
adding field names to the output is just as easy too! (a for loopw/fetch_feild() )
I have yet to see anything that easy for Windows/SQL server. My MFC book says it's too hard to do queries like that, so it doesn't cover it.
Anyone have any suggestions on wrappers?
|
|
|
|
|
Windows provides lots of way to get to data in databases but as you point out many of them are complex at least in the form provided by the system. I have used the CDatabase/CRecordset/CDaoDatabase, CDaoRecordset stuff from MFC, the ODBC api in straight C, ADO via smart pointers, ADO via straight COM, etc.
All of these do what you want but none with quite so few lines of code. I think they are designed to be more generic and powerful, but unfortunantely for many tasks they are just a pain in the butt.
I would take a look at the ADO library by Carlos Antollini (http://www.codeproject.com/database/caaadoclass1.asp). I have not used them myself but they appear to be quite simple and powerful.
If that doesn't work for you I have a set of class wrappers for ADO I developed a couple years ago which can do what you ask in fewer lines of code than you listed. I have not posted it here because it is not UNICODE compliant. Let me know if you would like the library and I will sent it to you with source code. It does not require MFC and this is basically how you would do what you asked:
CFPSADODatabase db("db", "uid", "pwd");
CFPSADORecordset rs(strSQL, db);
while (!rs.IsEOF())
{
for (iField = 0; iField < rs.GetFieldCount(); iField++)
printf(rs.GetFieldValueText(iField));
rs.MoveNext();
}
|
|
|
|
|
Is there a really good book on Windows Sockets that covers basics so low someone who hasn't programmed winsock before could understand but good enough to be the only resource I would need on the subject even for advanced topics?
|
|
|
|
|
|
Hello, the codegurus around the world.;)
If you go to amazon.com and search "WinSock", you will find some books
about Winsock.
Actually, even though I have bought a couple of books about WinSock,
I can't get the book which I want best.
So, sometimes I try to find some sample codes of WinSock in Internet.
Please, don't send me your email about your questions directly.
Have a nice day!
Sonork - 100.10571:vcdeveloper
-Masaaki Onishi-
|
|
|
|
|
I have an Win32 console application that does not have MFC and uses STL extensively.
I am facing a problem where the application quits without any warning or any message box. So, to debug I ran the app in the VC debug environment. Now the app does not quit, but shows a few lines in the output window that says
C0000096 Privileged Instruction
I believe that when running out of the environment, this causes the app to quit, but inside VC, VC handles this situation and lets the app run on. My problem is that since the execution does not stop, I have no way of finding out where this stuff occurs.
Any ideas?
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
runyour app, go to the Debug menu, choose Exceptions. find the "Priv instruction" exception in the list and check "Stop if not handled".
VC will kick into the debugger when the problem happens.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
You could try the old fashioned method of filling your code with extra printfs (i.e. "Entering function xxx()" "Exiting Function xxx()" ) so you can see a trace of what functions are being called. At least that way you'll be able to determine which function is causing the problem (which should allow you to place breakpoints and then debug it properly)
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
Does anyone know how to begin the code trace when a debug assertion fails under Windows XP Home? Under Win 98, if I ran my app in Debug build from the red exlamation point and an assertion failed, I got the popup dialog asking me to 'Abort', 'Retry', or 'Ignore.' If I pressed 'Retry', I was taken to the debug view where I could trace my code, watch variables, etc...
Now, under Win XP, the same dialog pops up, but if I click 'Retry', another dialog pops up telling me to press 'Cancel' to debug. If I do this, I get another dialog saying press 'OK' to terminate. I have no way of entering the debug view live.
Any help would be greatly appreciated as I've searched all over MSDN to no avial.
I'm running:
VS 6.0 with SP5
Win XP Home
Thanks
|
|
|
|
|
The red exclamation point icon "Executes" your app and won't attach the debugger. So clicking Retry on an assertion dialog won't get you into the debugger because it's not attached. I don't understand how you did it in Win 98 before. And I don't think this issue is OS dependent.
|
|
|
|
|
Thanks for the response. I'm not sure why, but "Executing" the app under Win 98 did allow for the "Retry" debugging. When I got a new computer with XP Home installed, I reinstalled VS 6.0 and SP5 just as I had under Win 98 and the only difference I noticed in VS was the inability to get into the debugger from "Execute."
Thanks to another response, I now know I can just use the "Go" command instead and that works fine.
Thanks again.
|
|
|
|
|
My 'Shellapi.h' NOTIFYICONDATA struct version doesn't support some functionality of W2K Shell_NotifyIcon().
if someone can pass me 'Shellapi.h' ver 5.0 or, tell me the values of these
constants:
NIM_SETFOCUS
NIF_STATE
NIS_HIDDEN
NIIF_WARNING
NIF_INFO
NIIF_ERROR
I'll be VERY greatful
--BlackSmith--
"With the help of all mighty", 2001, Me.
|
|
|
|
|
#define NIM_SETFOCUS 0x00000003
#define NIF_STATE 0x00000008
#define NIS_HIDDEN 0x00000001
#define NIIF_INFO 0x00000001
#define NIIF_WARNING 0x00000002
#define NIIF_ERROR 0x00000003
hope this helps
regards
Greg
modified 12-Sep-18 21:01pm.
|
|
|
|
|
#define NIM_SETFOCUS 0x4
#define NIF_STATE 0x8
#define NIS_HIDDEN 0x1
#define NIIF_WARNING 0x2
#define NIF_INFO 0x10
#define NIIF_ERROR 0x3
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi!
I can't install the latest Platform SDK. The setup reports this error:
"Setup has encountered an error
Another version of this product is installed, but its components cannot be located"
"You must uninstall the previous version of the Core SDK (Windows XP SP1) before Setup can continue. Choose OK to exit the Core SDK (Windows XP SP1) Setup Wizard, then use the Add/Remove Programs control panel to uninstall any previous versions"
What the hell does that mean? I had prevously installed the PSDK November 2001 and I wanted zo update it. I clicked on the item "Platform SDK November 2001" in the Add/Remove programs control panel. But this didn't seem to uninstall the SDK, since I still keep getting this error.
Any help is greatly appreciated
Greg
modified 12-Sep-18 21:01pm.
|
|
|
|
|
You need to remove certain registry settings. Look for registry setiings "Window SDK" or "Paltform SDK" under HKLM and delete it.
Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9
|
|
|
|
|
Hi,
I know how to create file with CreateFile() provide by SDK...
But with CFile !!!
I tried that :
CStdioFile newFile;
CFileException exc;
if(!newFile.Open("Backup.txt", CFile::modeCreate || CFile::modeWrite || CFile::typeText, &exc) ) {
exc.ReportError();
return;
}
and the result is a "File not found" Message box...
But I explicitly write : CFile::modeCreate !!!
Anybody can help me ?
Thanks for him...
Hello World!!!
from Raphaël
|
|
|
|
|
CStdioFile newFile;
CFileException exc;
if(!newFile.Open("Backup.txt", CFile::modeCreate | CFile::modeWrite | CFile::typeText, &exc) ) {
exc.ReportError();
return;
}
will work fine i guess, u have to pipe, not to logicaly or everything!
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Try
if(!newFile.Open("Backup.txt", CFile::modeCreate | CFile::modeWrite | CFile::typeText, &exc)
a single | instead of ||
Mike Mullikin - People demand freedom of speech as a compensation for the freedom of thought which they seldom use.
Soren Kierkegaard
|
|
|
|
|
I'm very stupid... logical OR is "|".... YES... of course... I know that... And now, It's OK... (stupid error)... I'm sleeping...
Thanks... Thanks... Thanks...
Hello World!!!
from Raphaël
|
|
|
|
|
Hi everyone,
I'm hoping someone can shed some light on the use of inheritance with dialog classes. I'm afraid that my situation is a bit tricky to describe. Please bear with me
I've designed a nice dialog (IDD_CEN_SEL). It will always have the same layout of buttons, edit boxes etc, but I want it to react to the user in various different ways. I thought that a good way to do this would be to use C++ inheritance/polymorphism. I created the dialog and the associated C++ class, CCenSelBase. I mplementd all of the constant functionality in the base class. I then created an inherited class CCenSelMapping : public CCenSelBase. This reacted to the user interface in certain specific ways. I also created a class CCenSelPlane : public CCenSelBase with slightly different functionality. This all worked nicely, and I was happy. Can you feel a 'But' coming...
But, I then created a new class CCenSelOffset : public CCenSelMapping. So I have a class inheriting from a class that inherits from the base class. Here's were it all gets very confusing.
here's some snippets of code:
BOOL DCenSelBase::OnInitDialog()
{
CDialog::OnInitDialog();
...
...
BOOL DCenSelMapper::OnInitDialog()
{
DCenSelBase::OnInitDialog();
InitTabs(m_tab);
...
...
BOOL DCenSelOffset::OnInitDialog()
{
DCenSelMapper::OnInitDialog();
...
...
CCenSelMapping uses DataExchange to get a member variable CTabCtrl m_tab, linked to a tab in the dialog. It initialises the tab within InitDialog().
So the tab initialisation code is called in DCenSelMapping::InitDialog(), via a call to DCenSelOffset::InitDialog(). But in DCenSelMapping::InitDialog() m_tab is not intialised (m_tab::m_Hwnd == NULL).
In the debugger, DCenSelOffset::m_tab.m_hWnd is valid, but DCenSelMapping::m_tab.m_hWnd == NULL.
Does this make any sense to anyone? I have a feeling I've described the problem really badly, so if anyone needs more clarification, please ask away.
Any help would be greatly appreciated,
TIA
Pete
|
|
|
|
|
Hi Pete,
It's hard to know whithout further information, but I got a hunch about what might be going on. Is by chance m_tab declared twice, both in DCenSelMapping and DCenSelOffset ? This could be causing the classes to "look" at different member objects.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Yes, m_tab is declared twice. Or rather, was. I just removed it from DCenSelOffset.
That didn't work
This got me thinking, and I /think/ I've worked out what was happening. m_tab was declared in DCenSelMapping, and included in the AFX_DATA_MAP. So when DCenSelBase::InitDialog() called Dialog::InitDialog(), it was only initialising the variables declared in DCenSelBase's AFX_DATA_MAP, so it didn't initialise the inherited class's AFX_DATA_MAP. So I now have m_tab as a member of CCenSelBase, and have added it to all 3 class's AFX_DATA_MAP. And it works.
Does my explaination seem plausible?
Anyway, to cut a long story short, it now works. Thanks for the help Joaquin.
Pete
|
|
|
|
|
Does my explaination seem plausible?
It does to me I guess you can also keep m_tab in DCenSelMapper and call UpdateData(FALSE) prior to InitTabs() .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I have stumbled up against a wall with this one and am hoping that someone else has already handled this. I am qualifying code that presently works on WinNT to ensure that it works the same on Win2K. For an owner draw combo box, the following code in the DrawItem method fails on Win2K, but only when the display option for 'transition effects in menus and tooltips' is turned on.
CDC* DeviceContextPointer = CDC::FromHandle(lpDrawItemStruct->hDC);
CWnd* DropDownWindowPointer = DeviceContextPointer->GetWindow();
When the option is turned off, the CWnd pointer has a non null value and points to a real honest to goodness window. When the option is turned on however, the CWnd pointer is NULL and rightly so because with the option turned on, the DrawItem method is invoked without a real honest to goodness window available to draw in. I think that part of the trouble is that the 'architecture' for owner draw stuff has changed and I need to jack around the code to reflect that. Any ideas or comments are appreciated. Thanks.
Chris Meech
|
|
|
|
|