Thread: [WIN32] Printing MySQL results

  1. #1
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115

    [WIN32] Printing MySQL results

    I'm writing a Win32 application that uses MySQL C API...(package MySQL for DevC++)...

    I got the connection, I can execute queries, but I don't know how to display results from a query(in main window)...?

    thanks for help!

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Either make your application a console window and use std::cout,

    or

    http://www.winprog.org/tutorial/

    gg

  3. #3
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    I managed to print the results into Listbox in a Dialog, but I've got few problems:

    1. If I only select ID from query, I've got about 7 lines for each row (some weird characters) and only one is ID.

    2. I can't use characters, used in windows-1250 encoding (characters are replaced by sings like ® © and so on....).

    Thanks for help in advance...

    Part of code:

    Code:
     
    char *query;
    query = "SELECT id FROM table";
    mysql_query(&mysql, query);
    result = mysql_store_result(&mysql);
    num = mysql_num_rows(result);
    while((row = mysql_fetch_row(result)))
    {
    	UINT length;
    	length = (UINT)mysql_fetch_lengths(result);
    	for(UINT i = 0; i < num; i++)
    	{
    	 SendDlgItemMessage(hwnd, IDC_LST1, LB_ADDSTRING, 0, (LPARAM)row[i]);
    	}
    Last edited by publikum; 01-27-2005 at 10:57 AM.
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

  4. #4
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Code:
    char *query;
    query = "SELECT id FROM table";
    mysql_query(&mysql, query);
    result = mysql_store_result(&mysql);
    num = mysql_num_rows(result);
    while((row = mysql_fetch_row(result))) // What's the datatype for the variable "row"?
    {
        UINT length;
        length = (UINT)mysql_fetch_lengths(result);
        for(UINT i = 0; i < num; i++)
        {
         SendDlgItemMessage(hwnd, IDC_LST1, LB_ADDSTRING, 0, (LPARAM)row[i]);
        }

  5. #5
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    It's MYSQL_ROW...

    But never mind...I figured out
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

  6. #6
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Wait! No! What was the answer?

  7. #7
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    Code:
     
    mysql_real_query(&mysql, query, strlen(query));
    result = mysql_store_result(&mysql);
    num = (UINT)mysql_num_fields(result);
    while(row = mysql_fetch_row(result))
    {
    	UINT *length;
    	length = (UINT *)mysql_fetch_lengths(result);
    	for(UINT i = 0; i < (UINT)num; i++)
    	{
    	 strncpy(data, row[i], (int)length[i]);
    	 SendDlgItemMessage(hwnd, IDC_LST1, LB_ADDSTRING, 0, (LPARAM)row[i]);
    	}
    }
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Printing Problem
    By silverlight001 in forum C# Programming
    Replies: 0
    Last Post: 03-23-2009, 01:13 AM
  2. Controlling variable values by printing on file
    By p3rry in forum C Programming
    Replies: 8
    Last Post: 12-17-2008, 10:09 AM
  3. MySQL libraries
    By csonx_p in forum C++ Programming
    Replies: 6
    Last Post: 10-02-2008, 02:23 AM
  4. Same seed for srand yields different results
    By codegirl in forum C++ Programming
    Replies: 3
    Last Post: 06-23-2003, 02:39 PM
  5. printing function results???
    By bluenoser in forum C Programming
    Replies: 1
    Last Post: 11-01-2002, 12:41 AM