Author Topic: SQL and 64 bits version  (Read 4463 times)

0 Members and 1 Guest are viewing this topic.

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
SQL and 64 bits version
« on: April 23, 2020, 04:28:52 am »
Hi,
I have finished the billing program with which I have taken several months. To do this I have used version 1.3 of 32 bits.
Now, I have decided to use the 64-bit version to see if it achieved a higher speed, and when compiling any of the programs I get the "cannot find dynamic library file" window.
In the QB64 folder I have copied the files: mysql.dll and msql_helper.h
Did I have to do something else, or does the SQL library not work in 64 bits?
Thank you

FellippeHeitor

  • Guest
Re: SQL and 64 bits version
« Reply #1 on: April 23, 2020, 07:55:56 am »
32bit version of QB64 can use 32bit version of a DLL. 64bit version of QB64 will require a 64bit version of said DLL.

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: SQL and 64 bits version
« Reply #2 on: April 23, 2020, 10:21:15 am »
And there is not a DLL64 bit version available?
Thank you

FellippeHeitor

  • Guest
Re: SQL and 64 bits version
« Reply #3 on: April 23, 2020, 11:26:36 am »
There probably is, but you'll need to look for it with their developer - where did you get the 32bit one?

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: SQL and 64 bits version
« Reply #4 on: April 23, 2020, 12:17:39 pm »
Is there a tutorial or thread about using QB64 with SQL?

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: SQL and 64 bits version
« Reply #5 on: April 23, 2020, 12:26:20 pm »
There probably is, but you'll need to look for it with their developer - where did you get the 32bit one?

At [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]. I think Galeon did it.
« Last Edit: April 23, 2020, 12:30:42 pm by Juanjogomez »

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: SQL and 64 bits version
« Reply #6 on: April 23, 2020, 12:32:38 pm »
Is there a tutorial or thread about using QB64 with SQL?

In a few minutes I will put the code that I use

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: SQL and 64 bits version
« Reply #7 on: April 23, 2020, 01:28:25 pm »
This is an example of code to use SQL...
In the QB64 folder must download 'mysql.dll' and create a text file called 'mysql_herper.h' with the following lines

void *offset_to_offset(void* offset){
  return offset;
 }
 void *offset_at_offset(void** offset){
 return *offset;
 }


Code: QB64: [Select]
  1.  
  2. DECLARE CUSTOMTYPE LIBRARY "mysql_helper"
  3.     FUNCTION offset_to_string$ ALIAS offset_to_offset (BYVAL offset AS _OFFSET)
  4.     FUNCTION offset_at_offset%& (BYVAL offset AS _OFFSET)
  5.  
  6. '---- download mysql.dll from http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/mysql.dll (~2MB) ----
  7.     FUNCTION mysql_init%& (BYVAL always_0 AS _OFFSET)
  8.     'MYSQL *mysql_init(MYSQL *mysql)
  9.     FUNCTION mysql_error$ (BYVAL mysql AS _OFFSET)
  10.     'const char *mysql_error(MYSQL *mysql)
  11.     FUNCTION mysql_get_client_info$
  12.     ' Returns a string that represents the client library version
  13.     ' const char *mysql_get_client_info(void)
  14.     FUNCTION mysql_real_connect%& (BYVAL mysql AS _OFFSET, host AS STRING, user AS STRING, password AS STRING, db AS STRING, BYVAL port AS _UNSIGNED LONG, BYVAL unix_socket AS _OFFSET, BYVAL client_flag AS _UNSIGNED _OFFSET)
  15.     FUNCTION mysql_real_connect_dont_open%& ALIAS mysql_real_connect (BYVAL mysql AS _OFFSET, host AS STRING, user AS STRING, password AS STRING, BYVAL db AS _OFFSET, BYVAL port AS _UNSIGNED LONG, BYVAL unix_socket AS _OFFSET, BYVAL client_flag AS _UNSIGNED LONG)
  16.     ' MYSQL *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 client_flag)
  17.     '  The value of host may be either a host name or an IP address. If host is NULL or the string "localhost", a connection to the local host is assumed.
  18.     '  db is the database name. If db is not NULL, the connection sets the default database to this value.
  19.     '  If port is not 0, the value is used as the port number for the TCP/IP connection. Note that the host parameter determines the type of the connection.
  20.     '  If unix_socket is not NULL, the string specifies the socket or named pipe to use. Note that the host parameter determines the type of the connection.
  21.     '  The value of client_flag is usually 0, but can be set to a combination of the following flags to enable certain features.
  22.     '  Return Value: A MYSQL* connection handle if the connection was successful, NULL if the connection was unsuccessful. For a successful connection, the return value is the same as the value of the first parameter.
  23.     '*** REMEMBER, ALL STRINGS PASSED MUST BE NULL '+CHR$(0)' TERMINATED ***
  24.     SUB mysql_query (BYVAL mysql AS _OFFSET, mysql_command AS STRING)
  25.     FUNCTION mysql_query& (BYVAL mysql AS _OFFSET, mysql_command AS STRING)
  26.     ' int mysql_query(MYSQL *mysql, const char *stmt_str)
  27.     ' Executes the SQL statement pointed to by the null-terminated string stmt_str. Normally, the string must consist of a single SQL statement without a terminating semicolon (%u201C;%u201D) or \g. If multiple-statement execution has been enabled,
  28.     'Returns Zero if the statement was successful. Nonzero if an error occurred.
  29.     '*** REMEMBER, ALL STRINGS PASSED MUST BE NULL '+CHR$(0)' TERMINATED ***
  30.     FUNCTION mysql_store_result%& (BYVAL mysql AS _OFFSET)
  31.     ' MYSQL_RES *mysql_store_result(MYSQL *mysql)
  32.     ' Returns a RESULT STRUCTURE
  33.     FUNCTION mysql_num_fields~& (BYVAL result AS _OFFSET)
  34.     ' unsigned int mysql_num_fields(MYSQL_RES *result)
  35.     ' To pass a MYSQL* argument instead, use unsigned int mysql_field_count(MYSQL *mysql).
  36.     ' Returns number of columns in result set
  37.     FUNCTION mysql_num_rows&& (BYVAL result AS _OFFSET)
  38.     ' my_ulonglong mysql_num_rows(MYSQL_RES *result)
  39.     ' Returns the number of rows in the result set.
  40.     FUNCTION mysql_fetch_row%& (BYVAL result AS _OFFSET)
  41.     ' MYSQL_ROW mysql_fetch_row(MYSQL_RES *result)
  42.     ' RETURNS A ROW STRUCTURE
  43.     FUNCTION mysql_fetch_lengths%& (BYVAL result AS _OFFSET)
  44.     ' unsigned long *mysql_fetch_lengths(MYSQL_RES *result)
  45.     ' Returns the lengths of the columns of the current row within a result set.
  46.     ' Returns a pointer to an array of lengths
  47.     SUB mysql_close (BYVAL mysql AS _OFFSET)
  48.     SUB mysql_free_result (BYVAL result AS _OFFSET)
  49.  
  50. '--Example to search for a data in a database called `books' that has the database table 'book' whidt fields: 'id', 'title', 'publisher' and 'author'
  51. my_server$ = "127.0.0.1"
  52. my_user$ = "root"
  53. my_key$ = "12345"
  54. bdatos$ = "books"
  55. port = 0
  56.  
  57. conn = mysql_init(0)
  58. REDIM SHARED DB_RESULT(columns, rows) AS STRING
  59.  
  60. IF conn = 0 THEN
  61.     PRINT "I can't start MYSQL client!": SLEEP (0): x$ = INKEY$
  62.  
  63. DIM conexion AS _OFFSET
  64.  
  65. '------ Open Database
  66. conexion = mysql_real_connect(conn, my_server$, my_user$, my_key$, bdatos$, port, 0, 0)
  67. IF conexion = 0 THEN PRINT "I cannot connect to the server": x$ = INPUT$(1)
  68.  
  69. '-- Search for Shakespeare books
  70. '-- Any SQL command could be used
  71. busclave$ = "SELECT * FROM book WHERE author = 'Shakespeare'" + CHR$(0)
  72. CALL basedato(busclave$, rows, columns)
  73. IF rows = 0 THEN
  74.     COLOR 4, 7
  75.     LOCATE 10, 10: PRINT " I can't find any book by that author ";
  76.     COLOR 15, 0
  77.     SLEEP 2: x$ = INKEY$
  78.     PRINT "Shakespeare's Books"
  79.     FOR n = 1 TO rows
  80.         PRINT "Title    :"; DB_RESULT(2, n)
  81.         PRINT "Publisher:"; DB_RESULT(3, n)
  82.         PRINT
  83.     NEXT
  84.  
  85.  
  86.  
  87. '----------------------------------------------------------- MYSQL -----------------------------------------------------------
  88. SUB basedato (busclave$, rows, columns)
  89.     '*** Hacer busqueda en la tabla ***
  90.     errf = mysql_query(conn, busclave$)
  91.     DIM result AS _OFFSET
  92.     'DIM columns AS LONG
  93.     result = mysql_store_result(conn)
  94.     IF LEFT$(busclave$, 6) = "SELECT" THEN
  95.         'DIM row AS _OFFSET
  96.         'DIM dato AS _OFFSET
  97.         columns = mysql_num_fields(result)
  98.         rows = mysql_num_rows(result)
  99.         '*** Guardar en Array ***
  100.         REDIM DB_RESULT(columns, rows) AS STRING
  101.         FOR filas = 1 TO rows
  102.             DIM mysql_row AS _OFFSET
  103.             mysql_row = mysql_fetch_row(result)
  104.             DIM mem_mysql_row AS _MEM
  105.             mem_mysql_row = _MEM(mysql_row, columns * LEN(an_offset%&)) 'The upper limit is unknown at this point
  106.             DIM mysql_lengths AS _OFFSET
  107.             mysql_lengths = mysql_fetch_lengths(result)
  108.             DIM mem_mysql_lengths AS _MEM
  109.             mem_mysql_lengths = _MEM(mysql_lengths, columns * 4)
  110.             DIM mem_field AS _MEM
  111.             FOR campos = 1 TO columns
  112.                 length = _MEMGET(mem_mysql_lengths, mem_mysql_lengths.OFFSET + (campos - 1) * 4, _UNSIGNED LONG)
  113.                 mem_field = _MEM(_MEMGET(mem_mysql_row, mem_mysql_row.OFFSET + (campos - 1) * LEN(an_offset%&), _OFFSET), length)
  114.                 DB_RESULT(campos, filas) = SPACE$(length)
  115.                 _MEMGET mem_field, mem_field.OFFSET, DB_RESULT(campos, filas)
  116.                 _MEMFREE mem_field
  117.             NEXT
  118.             _MEMFREE mem_mysql_lengths
  119.             _MEMFREE mem_mysql_row
  120.         NEXT
  121.     END IF
  122.     mysql_free_result result

I hope it works for you.
« Last Edit: April 23, 2020, 01:34:46 pm by Juanjogomez »

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: SQL and 64 bits version
« Reply #8 on: April 23, 2020, 02:38:41 pm »
Thank you Juanjogomez.
I will study your program.