NO

Recent Posts

Pages: [1] 2 3 ... 10
1
Beginner questions / Re: Using MySQL C Connector 6.1.11
« Last post by pjbrudal on October 15, 2017, 08:14:58 AM »
And after copying libmysql.dll from the connector folder to C:\Windows, the program also works :-) Thank you once more!
2
Beginner questions / Re: Using MySQL C Connector 6.1.11
« Last post by pjbrudal on October 15, 2017, 07:13:07 AM »
Thank you, guys. The project now builds without error messages.
3
Tips & tricks / MariaDB
« Last post by TimoVJL on October 13, 2017, 07:36:51 PM »
MariaDB have a support for GSSAPI.

WARNING:  auth_gssapi corrupted mysql.user files in my test, so take backup of data\mysql\user.* files for a recovery.

It is possible to run server as normal user without installing.

create users
Code: [Select]
> INSTALL SONAME 'auth_gssapi';
> CREATE USER test IDENTIFIED VIA gssapi;
After that code examples don't need username/password any more.
Code: [Select]
mysql_real_connect(con, "localhost", 0, 0, "test", 0, NULL, 0)
An example of basic usage from http://zetcode.com/db/mysqlc/
Code: [Select]
#include <stdio.h>
#include <stdlib.h>
//#include <mysql.h>
//#pragma comment(lib, "libmysql.lib")
#pragma comment(lib, "libmariadb.lib")
#ifndef _mysql_h
typedef void* MYSQL;
typedef void* MYSQL_RES;
typedef char **MYSQL_ROW;
#define STDCALL __stdcall
__declspec(dllimport) MYSQL * STDCALL mysql_init(MYSQL *mysql);
__declspec(dllimport) MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag);
__declspec(dllimport) int STDCALL mysql_query(MYSQL *mysql, const char *q);
__declspec(dllimport) MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
__declspec(dllimport) MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
__declspec(dllimport) const char * STDCALL mysql_error(MYSQL *mysql);
__declspec(dllimport) unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
__declspec(dllimport) void STDCALL mysql_free_result(MYSQL_RES *result);
__declspec(dllimport) void STDCALL mysql_close(MYSQL *sock);
#endif
// http://zetcode.com/db/mysqlc/
void finish_with_error(MYSQL *con)
{
fprintf(stderr, "%s\n", mysql_error(con));
mysql_close(con);
exit(1);
}

int main(int argc, char **argv)
{
MYSQL *con = mysql_init(0);

if (con == NULL)
{
fprintf(stderr, "mysql_init() failed\n");
exit(1);
}

// if (mysql_real_connect(con, "localhost", "", "", "test", 0, NULL, 0) == NULL)
if (mysql_real_connect(con, "localhost", 0, 0, "test", 0, NULL, 0) == NULL)
finish_with_error(con);

// if (mysql_query(con, "CREATE TABLE test (id INTEGER NOT NULL PRIMARY KEY, text VARCHAR(100))"))
// finish_with_error(con);

// if (mysql_query(con, "INSERT INTO test VALUES (1, 'text1')"))
// finish_with_error(con);

if (mysql_query(con, "SELECT * FROM test"))
finish_with_error(con);

MYSQL_RES *result = mysql_store_result(con);

if (result == NULL)
finish_with_error(con);

int num_fields = mysql_num_fields(result);

MYSQL_ROW row;

while ((row = mysql_fetch_row(result)) != NULL)
{
for (int i = 0; i < num_fields; i++)
{
printf("%s ", row[i] ? row[i] : "NULL");
}
printf("\n");
}

mysql_free_result(result);

mysql_close(con);
exit(0);
}

Test environment:
Code: [Select]
bin\
mysqld.exe
mysql_install_db.exe
mysql.exe
lib\
plugin\
auth_gssapi.dll
auth_gssapi_client.dll
share\
english\
errmsg.sys
1. create databases:
Code: [Select]
bin\mysql_install_db.exe --datadir=C:\code\MariaDB_10\data2. start database server:
Code: [Select]
bin\mysqld.exe --console3. start shell:
Code: [Select]
bin\mysql -u root
Code: [Select]
> INSTALL SONAME 'auth_gssapi'create users:
Code: [Select]
> CREATE USER user1 IDENTIFIED VIA gssapi;n. finally shutdown database server:
Code: [Select]
bin\mysqladmin -u root -p shutdown start database server again:
Code: [Select]
bin\mysqld.exe --consoleat this point we can see if everything went correctly.

MariaDB 10 mysqld starter kit ;)
4
Beginner questions / Re: Using MySQL C Connector 6.1.11
« Last post by frankie on October 13, 2017, 05:14:25 PM »
MariaDB have bugs in headers, varargs are not handled correctly.
Code: [Select]
Building TestMariaDB.obj.
C:\code\PellesC\MariaDB\include\mysql.h(444): warning #2203: Function 'mysql_load_plugin' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(495): warning #2203: Function 'mariadb_get_infov' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(572): warning #2203: Function 'mysql_optionsv' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(573): warning #2203: Function 'mysql_get_optionv' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(728): warning #2203: Function 'mariadb_get_infov' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(782): warning #2203: Function 'mysql_optionsv' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(783): warning #2203: Function 'mysql_get_optionv' can't be __stdcall, changed to __cdecl.
Building TestMariaDB.exe.
Done.
Build time: 750ms
That's are simple warnings, the problem is that MS compilers accepts also variadic functions declared as __stdcall.
Evidently the library was developed using MS...  >:(
5
Beginner questions / Re: Using MySQL C Connector 6.1.11
« Last post by TimoVJL on October 13, 2017, 03:48:09 PM »
This example didn't gave any errors with that MySQL connector 6.1.11
Code: [Select]
#include <stdio.h>
//#include <mysql.h>
#include "mysql.h" // only for the depedencies for the zip
#pragma comment(lib, "libmysql.lib")
//#pragma comment(lib, "libmariadb.lib")
int _cdecl main(int argc, char *argv[])
{
printf("Testing testing testing\n");
printf("MySQL client version: %s\n", mysql_get_client_info());
// printf("MariaDB client version: %s\n", mysql_get_client_info());
return 0;
}

MariaDB have bugs in headers, varargs are not handled correctly.
Code: [Select]
Building TestMariaDB.obj.
C:\code\PellesC\MariaDB\include\mysql.h(444): warning #2203: Function 'mysql_load_plugin' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(495): warning #2203: Function 'mariadb_get_infov' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(572): warning #2203: Function 'mysql_optionsv' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(573): warning #2203: Function 'mysql_get_optionv' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(728): warning #2203: Function 'mariadb_get_infov' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(782): warning #2203: Function 'mysql_optionsv' can't be __stdcall, changed to __cdecl.
C:\code\PellesC\MariaDB\include\mysql.h(783): warning #2203: Function 'mysql_get_optionv' can't be __stdcall, changed to __cdecl.
Building TestMariaDB.exe.
Done.
Build time: 750ms
6
Beginner questions / Re: Using MySQL C Connector 6.1.11
« Last post by pjbrudal on October 13, 2017, 01:12:41 PM »
I have selected Enable Microsoft extensions in the compiler tag in project options. Shouldn't that be sufficient?
All my libraries are for X86 architecture, not for X64. And for Windows, not for Unix :-)

There are 2 separate problems: one with _stcall versus _cdecl and one with the library and the function names.

Have anyone else tried MySQL with Pelles C recently? I have read Jan Bodnar's tutorial, and used his examples, but it just won't work.
7
Beginner questions / Re: Using MySQL C Connector 6.1.11
« Last post by TimoVJL on October 13, 2017, 10:03:13 AM »
use pocc.exe option -Ze Enable Microsoft extensions
and check correct library libmysql.lib/libmariadb.lib is it for i386 ?
8
Beginner questions / Re: Using MySQL C Connector 6.1.11
« Last post by pjbrudal on October 13, 2017, 08:55:28 AM »
Thanks a lot for the advice, which unfortunately didn't help in any way.
a) The file crtdbg.h is part of Microsoft Visual Studio, which I don't have. It is included from the file my_global.h, which is part of Oracle's MySQL C connector. Based on advice from another forum on the internet, I wrote a small crtdbg.h stub and put it in the connector's include folder. However, I just got other problems later in the compilation. So I dropped the my_global.h and used stdio.h, windows.h and winsock.h instead.
b) I have indeed added the include and lib folders to the Folder tag in Project Options, - and I know that C and C++ are different :-)
c) I have also got all the files that came with the MySQL connector.

Today changed the folder options to use the MariaDB C connector instead. This failed in a somewhat similar way as with Oracle's MySQL, as can be seen from the attachment. There are two problem areas:
Compiler: I get complaints about _stdcall used instead of _cdecl in some places in mysql.h. Do I need to include some other header files?
Linker: I get an error message that I guess has something to do with a 'decorated' function name. How can get the names to match?

I haven't used C for 15 years and I assume that things have changed over the years. And this is the first time I use Pelles C. I suspect there is something very simple that I've overlooked.
9
Beginner questions / Re: Using MySQL C Connector 6.1.11
« Last post by TimoVJL on October 12, 2017, 07:07:44 PM »
missing libmysql.lib ?

Usually this in source helps to remember what libraries program needs.
Code: [Select]
#include <mysql.h>
#pragma comment(lib, "libmysql.lib")
10
Beginner questions / Re: Using MySQL C Connector 6.1.11
« Last post by frankie on October 12, 2017, 06:02:31 PM »
Quote
Building Test.exe.
POLINK: error: Unresolved external symbol '_mysql_get_client_info@0'.
POLINK: fatal error: 1 unresolved external(s).
*** Error code: 1 ***
Done.
Have added the mysql connector library to the linker?
Have you used the C connector, not the C++ connector library?
Pages: [1] 2 3 ... 10