Jump to content
ProgAndy

MySQL UDFs (without ODBC)

Recommended Posts

Thanks, I will try to modify it to suit my needs

Regards

:EDIT

@ProgAndy

Its done! MySQL_Ping($MySQLConn) does the trick. Using Adlib, I can call MySQL_Ping() every 5 minutes to check the server. I'm so glad it can be done... :idea:

Edited by slayerz

AUTOIT[sup] I'm lovin' it![/sup]

Share this post


Link to post
Share on other sites

MySQL UDFs

using libmysql.dll

functions: most functions from MySQL API

all are prefixed with an underscore: _MySql... e.g.: _MySQL_Real_Query(

sometimes parameters are chaged - read function descriptions in include file MySQL.au3

not included:

I included a fallback-libmysql.dll: yoou can include libMySQLDLL.au3 and set $Use_EmbeddedDLL=True when calling _MySQL_InitLibrary

an example for XAMPP / cdcol is also included in ZIP.

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.8.1 (beta)
    Author:         Prog@ndy
    
    Script Function:
    MySQL-Plugin Demo Script
    
#ce ----------------------------------------------------------------------------

#include <array.au3>
#include "mysql.au3"

; MYSQL starten, DLL im PATH (enthält auch @ScriptDir), sont Pfad zur DLL angeben. DLL muss libmysql.dll heißen.
_MySQL_InitLibrary()
If @error Then Exit MsgBox(0, '', "could nit init MySQL")
MsgBox(0, "DLL Version:",_MySQL_Get_Client_Version()&@CRLF& _MySQL_Get_Client_Info())

$MysqlConn = _MySQL_Init()

;Fehler Demo:
MsgBox(0,"Error-demo","Error-Demo")
$connected = _MySQL_Real_Connect($MysqlConn,"localhostdfdf","droot","","cdcol")
If $connected = 0 Then
    $errno = _MySQL_errno($MysqlConn)
    MsgBox(0,"Error:",$errno & @LF & _MySQL_error($MysqlConn))
    If $errno = $CR_UNKNOWN_HOST Then MsgBox(0,"Error:","$CR_UNKNOWN_HOST" & @LF & $CR_UNKNOWN_HOST)
Endif

; XAMPP cdcol
MsgBox(0, "XAMPP-Cdcol-demo", "XAMPP-Cdcol-demo")

$connected = _MySQL_Real_Connect($MysqlConn, "localhost", "root", "", "cdcol")
If $connected = 0 Then Exit MsgBox(16, 'Connection Error', _MySQL_Error($MysqlConn))

$query = "SELECT * FROM cds"
$mysql_bool = _MySQL_Real_Query($MysqlConn, $query)
If $mysql_bool = $MYSQL_SUCCESS Then
    MsgBox(0, '', "Query OK")
Else
    $errno = _MySQL_errno($MysqlConn)
    MsgBox(0,"Error:",$errno & @LF & _MySQL_error($MysqlConn))
EndIf

$res = _MySQL_Store_Result($MysqlConn)

$fields = _MySQL_Num_Fields($res)

$rows = _MySQL_Num_Rows($res)
MsgBox(0, "", $rows & "-" & $fields)

; Access2 1
MsgBox(0, '', "Access method 1- manual")
Dim $array[$rows][$fields]
For $k = 1 To $rows
    $mysqlrow = _MySQL_Fetch_Row($res,$fields)

    $lenthsStruct = _MySQL_Fetch_Lengths($res)

    For $i = 1 To $fields
        $length = DllStructGetData($lenthsStruct, 1, $i)
        $fieldPtr = DllStructGetData($mysqlrow, 1, $i)
        $data = DllStructGetData(DllStructCreate("char[" & $length & "]", $fieldPtr), 1)
        $array[$k - 1][$i - 1] = $data
    Next
Next
_ArrayDisplay($array)

; Access 2
MsgBox(0, '', "Access method 2 - row for row")
_MySQL_Data_Seek($res, 0) ; just reset the pointer to the beginning of the result set
Do
$row1 = _MySQL_Fetch_Row_StringArray($res)
If @error Then ExitLoop
_ArrayDisplay($row1)
Until @error

; Access 3
MsgBox(0, '', "Access method 3 - read whole result in 2D-Array")
$array = _MySQL_Fetch_Result_StringArray($res)
_ArrayDisplay($array)

; fieldinfomation
MsgBox(0, '', "Access fieldinformation")
Dim $arFields[$fields][3]
For $i = 0 To $fields - 1
    $field = _MySQL_Fetch_Field_Direct($res, $i)
    $arFields[$i][0] = _MySQL_Field_ReadValue($field, "name")
    $arFields[$i][1] = _MySQL_Field_ReadValue($field, "table")
    $arFields[$i][2] = _MySQL_Field_ReadValue($field, "db")
Next
_ArrayDisplay($arFields)

; free result
_MySQL_Free_Result($res)

; Close connection
_MySQL_Close($MysqlConn)
; exit MYSQL
_MySQL_EndLibrary()

MySQL UDf Downloads:Posted Image

//Edit: updated DL-Link

Download link is broken. Please reupload this UDF

Share this post


Link to post
Share on other sites

I know. The server is currently down.

Here is a mirror.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Is it meant to stop me from using GUI controls/functions?

I can only use a MsgBox, and when I try to use GUICreate & GUICtrlCreateLabel nothing comes up (Not even a MsgBox)

?

This is really annoying because if this is the case I will be left helpless, as I need theese for my main part!

Share this post


Link to post
Share on other sites

Is it meant to stop me from using GUI controls/functions?

I can only use a MsgBox, and when I try to use GUICreate & GUICtrlCreateLabel nothing comes up (Not even a MsgBox)

?

This is really annoying because if this is the case I will be left helpless, as I need theese for my main part!

This UDF should not interfere with other functions. You must have some errors in your code.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Just added a download link for the x64-dll which is needed for usage on Windows x64. I am not able to test whether it functions properly since I have no suitable OS.

Edit: the dll must always be named libmysql.dll, I'll have to modfy the udf to change this.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Hi ProgAndy,

I used your MySQL UDF working on XML (HTML) data field, it works wrong.

You can test this data which is one field of record:

<?xml version="1.0" encoding="utf-8"?>
<document>
  <title>Poor and Poverty; Wealthy and Wealth</title>
  <subhead></subhead>
  <navigation>Confusing Words Vocabulary</navigation>
  <content>
    <![CDATA[
<div class="content">
  <p>
        </P>
  <p>
    When someone does not have money we can say they are
    <span class="style5">
      poor
                </SPAN>
    . It is an adjective.
    <br />
    <span class="style3">
      "A poor man."
                </SPAN>
        </P>
  <p>
    The noun form of poor is
    <span class="style1">
      <strong>
        poverty
                        </STRONG>
                </SPAN>
    .
    <br />
    <span class="style3">
      "Many people in the world still live in poverty."
                </SPAN>
        </P>
  <p>
    The comparative form is
    <span class="style5">
      poorer
                </SPAN>
    , not more poor.
    <br />
    <span class="style3">
      "I am poorer than David."
                </SPAN>
        </P>
  <p>
    The superlative form is
    <span class="style5">
      poorest
                </SPAN>
    .
    <br />
    <span class="style3">
      "The poorest countries are in Africa."
                </SPAN>
        </P>
  <p>
    You may know that the opposite of poor is rich, yet we can also use
    <span class="style1">
      <strong>
        wealthy
                        </STRONG>
                </SPAN>
    as an opposite of poor.
    <br />
    <span class="style3">
      "Only very wealthy people can afford to eat here."
                </SPAN>
        </P>
  <p>
    The noun form of wealthy is
    <span class="style5">
      wealth
                </SPAN>
    .
    <br />
    <span class="style3">
      "Over her career, she accumulated a great amount of wealth."
                </SPAN>
        </P>
  <p>
    The comparative form is
    <span class="style5">
      wealthier
                </SPAN>
    , not more wealthy.
    <br />
    <span class="style3">
      "I am wealthier now than I was 5 years ago."
                </SPAN>
        </P>
  <p>
    The superlative form is
    <span class="style5">
      wealthiest
                </SPAN>
    .
    <br />
    <span class="style3">
      "Is Bill Gates the wealthiest person in the world?"
                </SPAN>
        </P>
  <p>
        </P>
  <ul id="exerciseanswers">
    <li id='0lianswer'>
      <strong>
        1 - Governments are working toward ending world ___.
                        </STRONG>
      <br />
      <span class='answer' id='0answerspan'>
                        </SPAN>
      <div class='mcanswers'>
        <input type="hidden" name="0canswer" id="0canswer" />
        <label>
          <input onclick="document.getElementById('0canswer').value = this.value;" type="radio" name="0radio" id="00radio" value="poorer" />
          poorer
                                </LABEL>
        <br />
        <label>
          <input onclick="document.getElementById('0canswer').value = this.value;" type="radio" name="0radio" id="01radio" value="poverty" />
          poverty
                                </LABEL>
        <br />
        <label>
          <input onclick="document.getElementById('0canswer').value = this.value;" type="radio" name="0radio" id="02radio" value="poor" />
          poor
                                </LABEL>
        <br />
        <br />
                        </DIV>
                </LI>
    <li id='1lianswer'>
      <strong>
        2 - What is the ___ country in the world?
                        </STRONG>
      <br />
      <span class='answer' id='1answerspan'>
                        </SPAN>
      <div class='mcanswers'>
        <input type="hidden" name="1canswer" id="1canswer" />
        <label>
          <input onclick="document.getElementById('1canswer').value = this.value;" type="radio" name="1radio" id="10radio" value="poorest" />
          poorest
                                </LABEL>
        <br />
        <label>
          <input onclick="document.getElementById('1canswer').value = this.value;" type="radio" name="1radio" id="11radio" value="poverty" />
          poverty
                                </LABEL>
        <br />
        <label>
          <input onclick="document.getElementById('1canswer').value = this.value;" type="radio" name="1radio" id="12radio" value="poor" />
          poor
                                </LABEL>
        <br />
        <label>
          <input onclick="document.getElementById('1canswer').value = this.value;" type="radio" name="1radio" id="13radio" value="poorer" />
          poorer
                                </LABEL>
        <br />
        <br />
                        </DIV>
                </LI>
    <li id='2lianswer'>
      <strong>
        3 - I come from a ___ family.
                        </STRONG>
      <br />
      <span class='answer' id='2answerspan'>
                        </SPAN>
      <div class='mcanswers'>
        <input type="hidden" name="2canswer" id="2canswer" />
        <label>
          <input onclick="document.getElementById('2canswer').value = this.value;" type="radio" name="2radio" id="20radio" value="poorest" />
          poorest
                                </LABEL>
        <br />
        <label>
          <input onclick="document.getElementById('2canswer').value = this.value;" type="radio" name="2radio" id="21radio" value="poor" />
          poor
                                </LABEL>
        <br />
        <label>
          <input onclick="document.getElementById('2canswer').value = this.value;" type="radio" name="2radio" id="22radio" value="poverty" />
          poverty
                                </LABEL>
        <br />
        <br />
                        </DIV>
                </LI>
    <li id='3lianswer'>
      <strong>
        4 - Are people today ___ than they were in the past?
                        </STRONG>
      <br />
      <span class='answer' id='3answerspan'>
                        </SPAN>
      <div class='mcanswers'>
        <input type="hidden" name="3canswer" id="3canswer" />
        <label>
          <input onclick="document.getElementById('3canswer').value = this.value;" type="radio" name="3radio" id="30radio" value="poorest" />
          poorest
                                </LABEL>
        <br />
        <label>
          <input onclick="document.getElementById('3canswer').value = this.value;" type="radio" name="3radio" id="31radio" value="poor" />
          poor
                                </LABEL>
        <br />
        <label>
          <input onclick="document.getElementById('3canswer').value = this.value;" type="radio" name="3radio" id="32radio" value="poorer" />
          poorer
                                </LABEL>
        <br />
        <br />
                        </DIV>
                </LI>
    <li id='4lianswer'>
      <strong>
        5 - She dreams of being ___.
                        </STRONG>
      <br />
      <span class='answer' id='4answerspan'>
                        </SPAN>
      <div class='mcanswers'>
        <input type="hidden" name="4canswer" id="4canswer" />
        <label>
          <input onclick="document.getElementById('4canswer').value = this.value;" type="radio" name="4radio" id="40radio" value="wealthy" />
          wealthy
                                </LABEL>
        <br />
        <label>
          <input onclick="document.getElementById('4canswer').value = this.value;" type="radio" name="4radio" id="41radio" value="wealth" />
          wealth
                                </LABEL>
        <br />
        <br />
                        </DIV>
                </LI>
    <li id='5lianswer'>
      <strong>
        6 - Russia has a lot of mineral ___.
                        </STRONG>
      <br />
      <span class='answer' id='5answerspan'>
                        </SPAN>
      <div class='mcanswers'>
        <input type="hidden" name="5canswer" id="5canswer" />
        <label>
          <input onclick="document.getElementById('5canswer').value = this.value;" type="radio" name="5radio" id="50radio" value="wealthy" />
          wealthy
                                </LABEL>
        <br />
        <label>
          <input onclick="document.getElementById('5canswer').value = this.value;" type="radio" name="5radio" id="51radio" value="wealth" />
          wealth
                                </LABEL>
        <br />
        <br />
                        </DIV>
                </LI>
    <li id='6lianswer'>
      <strong>
        7 - Who is the ___ person you know?
                        </STRONG>
      <br />
      <span class='answer' id='6answerspan'>
                        </SPAN>
      <div class='mcanswers'>
        <input type="hidden" name="6canswer" id="6canswer" />
        <label>
          <input onclick="document.getElementById('6canswer').value = this.value;" type="radio" name="6radio" id="60radio" value="wealthier" />
          wealthier
                                </LABEL>
        <br />
        <label>
          <input onclick="document.getElementById('6canswer').value = this.value;" type="radio" name="6radio" id="61radio" value="wealthiest" />
          wealthiest
                                </LABEL>
        <br />
        <br />
                        </DIV>
                </LI>
    <li id='7lianswer'>
      <strong>
        8 - She's much ___ than me.
                        </STRONG>
      <br />
      <span class='answer' id='7answerspan'>
                        </SPAN>
      <div class='mcanswers'>
        <input type="hidden" name="7canswer" id="7canswer" />
        <label>
          <input onclick="document.getElementById('7canswer').value = this.value;" type="radio" name="7radio" id="70radio" value="wealthiest" />
          wealthiest
                                </LABEL>
        <br />
        <label>
          <input onclick="document.getElementById('7canswer').value = this.value;" type="radio" name="7radio" id="71radio" value="wealthier" />
          wealthier
                                </LABEL>
        <br />
        <br />
                        </DIV>
                </LI>
        </UL>
  <script type="text/javascript">
    function checkanswers(){

if(document.getElementById('0canswer').value.toLowerCase().replace(/'/, ''') == 'poverty'){document.getElementById('0answerspan').innerHTML = 'Correct!';document.getElementById('0lianswer').className = 'correct';}else{document.getElementById('0answerspan').innerHTML = 'Wrong!';document.getElementById('0lianswer').className = 'wrong';}if(document.getElementById('1canswer').value.toLowerCase().replace(/'/, ''') == 'poorest'){document.getElementById('1answerspan').innerHTML = 'Correct!';document.getElementById('1lianswer').className = 'correct';}else{document.getElementById('1answerspan').innerHTML = 'Wrong!';document.getElementById('1lianswer').className = 'wrong';}if(document.getElementById('2canswer').value.toLowerCase().replace(/'/, ''') == 'poor'){document.getElementById('2answerspan').innerHTML = 'Correct!';document.getElementById('2lianswer').className = 'correct';}else{document.getElementById('2answerspan').innerHTML = 'Wrong!';document.getElementById('2lianswer').className = 'wrong';}if(document.getElementById('3canswer').value.toLowerCase().replace(/'/, ''') == 'poorer'){document.getElementById('3answerspan').innerHTML = 'Correct!';document.getElementById('3lianswer').className = 'correct';}else{document.getElementById('3answerspan').innerHTML = 'Wrong!';document.getElementById('3lianswer').className = 'wrong';}if(document.getElementById('4canswer').value.toLowerCase().replace(/'/, ''') == 'wealthy'){document.getElementById('4answerspan').innerHTML = 'Correct!';document.getElementById('4lianswer').className = 'correct';}else{document.getElementById('4answerspan').innerHTML = 'Wrong!';document.getElementById('4lianswer').className = 'wrong';}if(document.getElementById('5canswer').value.toLowerCase().replace(/'/, ''') == 'wealth'){document.getElementById('5answerspan').innerHTML = 'Correct!';document.getElementById('5lianswer').className = 'correct';}else{document.getElementById('5answerspan').innerHTML = 'Wrong!';document.getElementById('5lianswer').className = 'wrong';}if(document.getElementById('6canswer').value.toLowerCase().replace(/'/, ''') == 'wealthiest'){document.getElementById('6answerspan').innerHTML = 'Correct!';document.getElementById('6lianswer').className = 'correct';}else{document.getElementById('6answerspan').innerHTML = 'Wrong!';document.getElementById('6lianswer').className = 'wrong';}if(document.getElementById('7canswer').value.toLowerCase().replace(/'/, ''') == 'wealthier'){document.getElementById('7answerspan').innerHTML = 'Correct!';document.getElementById('7lianswer').className = 'correct';}else{document.getElementById('7answerspan').innerHTML = 'Wrong!';document.getElementById('7lianswer').className = 'wrong';}}
        </SCRIPT>
  <br />
  <br />
  <input name="Check_Answers" type="button" onclick="checkanswers();" value="Check Answers" />
  <br />
  <br />
</DIV>]]>
  </content>
  <comment>
    <![CDATA[
<div class="content">
  <p>
    It is easy, especially with such brilliant explanation!!!!
    <IMG src="http://www.ecenglish.com/learnenglish/modules/smileys/packs/Yahoo!/clap.gif" title="Applause" alt="Applause">
    <br />
    Thank you for the Lesson!
    <IMG src="http://www.ecenglish.com/learnenglish/modules/smileys/packs/Yahoo!/smile.gif" title="Smile" alt="Smile">
        </P>
</DIV>]]>
  </comment>
  <comment>
    <![CDATA[
<div class="content">
  <p>
    Also it's a good point to know that "wealth" is uncountable noun.
    <br />
    e.g. "a great amount of wealth"
        </P>
</DIV>]]>
  </comment>
  <comment>
    <![CDATA[
<div class="content">
  <p>
    It is a very easy lesson, as for me. But it's very interesting.
        </P>
</DIV>]]>
  </comment>
  <comment>
    <![CDATA[
<div class="content">
  <p>
    easy exercise..nice only this sexercise i got full
    <IMG src="http://www.ecenglish.com/learnenglish/modules/smileys/packs/Yahoo!/whew.gif" title="Whew!" alt="Whew!">
        </P>
</DIV>]]>
  </comment>
  <src><![CDATA[http://www.ecenglish.com/learnenglish/lessons/poor-and-poverty-wealth-and-wealthy]]></src>
</document>
Other tested data: http://www.mediafire.com/?njfzzvdt0oj . It clearly see that some data don't load.

Can you fix this problem? I hope so, I need your UDF working on XML data.

Edited by SmOke_N

Share this post


Link to post
Share on other sites

New version with a bugfix in _MySQL_Fetch_Fields_Names. Download in first post.

Edit: This error had also effects on some other functions using this function internally, so update :mellow:

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Hi ProgAndy,

I used your MySQL UDF working on XML (HTML) data field, it works wrong.

You can test this data which is one field of record:

Other tested data: http://www.mediafire.com/?njfzzvdt0oj . It clearly see that some data don't load.

Can you fix this problem? I hope so, I need your UDF working on XML data.

I Can't see any problem. _ArrayDisplay doesn't display everything, but the data itself is fine. Just try MsgBoxes :mellow:

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Hi! I'm really new at this and I need some help translating a php-code, if it's possible.

$q = "SELECT id, name, kat FROM prod WHERE kat = '$kat' ORDER BY 'name'";
$r = mysql_query($q);
while (list($id, $name, $kat) = mysql_fetch_array($r)) {
;---code here
}

I would really appreciate if someone could look into this.

Edited by Bonchen

Share this post


Link to post
Share on other sites

OK, I'll do it since this could help othres to understand the function better, too:

_MySQL_InitLibrary()
OnAutoItExitRegister("_FreeResources")
Func _FreeResources()
    _MySQL_EndLibrary()
EndFunc

$hMySQL = _MySQL_Init()
If _MySQL_Real_Connect($hMySQL, "Server.address", "username", "password", "database") Then
    $kat = _MySQL_Real_Escape_String($hMySQL, $kat)
    If $MYSQL_SUCCESS = _MySQL_Real_Query($hMySQL, "SELECT id, name, kat FROM prod WHERE kat = '"&$kat&"' ORDER BY 'name'") Then
        $hResult = _MySQL_Store_Result($hMySQL)
        If $hResult Then
            $iFields = _MySQL_Num_Fields($hResult)
            While $iFields>0
                $asRow = _MySQL_Fetch_Row_StringArray($hResult, $iFields)
                If @error Then ExitLoop
                $id = $asRow[0]
                $name = $asRow[1]
                $kat = $asRow[2]                
                MsgBox(0, "" $id & @CRLF & $name & @CRLF & $kat)
            WEnd
            _MySQL_Free_Result($hResult)
        EndIf
    EndIf
EndIf
_MySQL_Close($hMySQL)
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

OK, I'll do it since this could help othres to understand the function better, too:

_MySQL_InitLibrary()
OnAutoItExitRegister("_FreeResources")
Func _FreeResources()
    _MySQL_EndLibrary()
EndFunc

$hMySQL = _MySQL_Init()
If _MySQL_Real_Connect($hMySQL, "Server.address", "username", "password", "database") Then
    $kat = _MySQL_Real_Escape_String($hMySQL, $kat)
    If $MYSQL_SUCCESS = _MySQL_Real_Query($hMySQL, "SELECT id, name, kat FROM prod WHERE kat = '"&$kat&"' ORDER BY 'name'") Then
        $hResult = _MySQL_Store_Result($hMySQL)
        If $hResult Then
            $iFields = _MySQL_Num_Fields($hResult)
            While $iFields>0
                $asRow = _MySQL_Fetch_Row_StringArray($hResult, $iFields)
                If @error Then ExitLoop
                $id = $asRow[0]
                $name = $asRow[1]
                $kat = $asRow[2]                
                MsgBox(0, "" $id & @CRLF & $name & @CRLF & $kat)
            WEnd
            _MySQL_Free_Result($hResult)
        EndIf
    EndIf
EndIf
_MySQL_Close($hMySQL)

You're an angel! Thank you.

Share this post


Link to post
Share on other sites

There was an error on last upload of the zip-file, so the x64-version wasn't availbale.

Please download the library again.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

OK, I'll do it since this could help othres to understand the function better, too:

_MySQL_InitLibrary()
OnAutoItExitRegister("_FreeResources")
Func _FreeResources()
    _MySQL_EndLibrary()
EndFunc

$hMySQL = _MySQL_Init()
If _MySQL_Real_Connect($hMySQL, "Server.address", "username", "password", "database") Then
    $kat = _MySQL_Real_Escape_String($hMySQL, $kat)
    If $MYSQL_SUCCESS = _MySQL_Real_Query($hMySQL, "SELECT id, name, kat FROM prod WHERE kat = '"&$kat&"' ORDER BY 'name'") Then
        $hResult = _MySQL_Store_Result($hMySQL)
        If $hResult Then
            $iFields = _MySQL_Num_Fields($hResult)
            While $iFields>0
                $asRow = _MySQL_Fetch_Row_StringArray($hResult, $iFields)
                If @error Then ExitLoop
                $id = $asRow[0]
                $name = $asRow[1]
                $kat = $asRow[2]                
                MsgBox(0, "" $id & @CRLF & $name & @CRLF & $kat)
            WEnd
            _MySQL_Free_Result($hResult)
        EndIf
    EndIf
EndIf
_MySQL_Close($hMySQL)

thanks that really helped

Share this post


Link to post
Share on other sites

OK, I'll do it since this could help othres to understand the function better, too:

_MySQL_InitLibrary()
OnAutoItExitRegister("_FreeResources")
Func _FreeResources()
    _MySQL_EndLibrary()
EndFunc

$hMySQL = _MySQL_Init()
If _MySQL_Real_Connect($hMySQL, "Server.address", "username", "password", "database") Then
    $kat = _MySQL_Real_Escape_String($hMySQL, $kat)
    If $MYSQL_SUCCESS = _MySQL_Real_Query($hMySQL, "SELECT id, name, kat FROM prod WHERE kat = '"&$kat&"' ORDER BY 'name'") Then
        $hResult = _MySQL_Store_Result($hMySQL)
        If $hResult Then
            $iFields = _MySQL_Num_Fields($hResult)
            While $iFields>0
                $asRow = _MySQL_Fetch_Row_StringArray($hResult, $iFields)
                If @error Then ExitLoop
                $id = $asRow[0]
                $name = $asRow[1]
                $kat = $asRow[2]                
                MsgBox(0, "" $id & @CRLF & $name & @CRLF & $kat)
            WEnd
            _MySQL_Free_Result($hResult)
        EndIf
    EndIf
EndIf
_MySQL_Close($hMySQL)

I really love this UDF and praise ProgAndy for maintaining support. I'm not here to complain, just find a better way of doing things. Particularly with error handling with this UDF.

@ProgAndy or anyone with enough experience with this UDF, is there a better way of escaping the while loop than simply "If @error Then ExitLoop"? Better yet, is there any documentation or manual for this UDF that explains the behavior that has my answer within? This method of error detection works, but really doesn't allow for robust error handling or maintaining data flow after an unexpected error occurrence. I know if I want robust one could argue that I should have selected a different language or code, so please omit comments regarding that for now. I just enjoy using AutoIt for many daily tasks. :)

Update: I've found the function _MySQL_Fetch_Row_StringArray() inside of the MySql.au3 file. The behavior seems to be to set @error = 1 when no more rows exist as well as setting the $array return value as zero. I suppose this is sufficient and I just need to stop whining and get used to it! ;)

I think I've been spoiled by the Sqlite method of escaping a while loop which is to get a return value to compare to a constant like so:

While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK

; Do stuff with the data

msgbox(0,"","Fresh from the HDD " & $aRow[1] & ". With a side order of " & $aRow[1] & ".")

WEnd

Update2: I've found another method that satisfies exiting the loop independent of the value of @error:

$asRow = _MySQL_Fetch_Row_StringArray($hResult, $iFields)
; Substitute this where line "If @error Then ExitLoop once was
If IsArray($asRow) Then
    ; Do your thing
Else
    ; The great escape
    ExitLoop
EndIf

Edit: Cleared up comment to relieve confusion

Not saying that is the better way of doing things. In fact I'm asking for someone to knock me logically silly if I'm wrong.

Update 3:

I found functional way to detect errors on the query and even for the connection, but still not sure about the best way to exit out the while loop when iterating through the rows.

Error handling on the query:

If $MYSQL_SUCCESS = _MySQL_Real_Query($hMySQL, "SELECT This, That FROM alittleofeverything WHERE This='this' AND That='that'") Then
; Do stuff
Else
; Raise error handling, in this case just a message
MsgBox(0,"","Error Number: " & _MySQL_errno($hMySqlConnection) & @CRLF & "Error Message: " & _MySQL_Error($hMySqlConnection))
EndIf
Edited by Sn3akyP3t3

Share this post


Link to post
Share on other sites

I have tried all of the links in this topic. I was not able to download the UDF from any of them. Is there a new location?

@ProgAndy, If you need a place to host the UDF, let me know. I would be happy to host this one on my server.

Share this post


Link to post
Share on other sites

@willichan: Please read my signature. The download is currently here: ---

Edit: Domain is back.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

HI all

My code is failing on the InitLibrary statement.

I notice when looking in the include file that it attempts to check the client version. Am I to assume that this script must run on the same server as the MySQL database is running on? (i.e. it won't work across the network?)

TIA

Clark

Share this post


Link to post
Share on other sites

HI all

My code is failing on the InitLibrary statement.

Same thing for me. I can't even get the library loaded, let alone make any MySQL Queries.

I extracted the files from your download into the includes folder, and have been trying to initialize the library. But all I get is errors. I would great appreciate any kind of help from anyone on this topic. I'm desperate to have MySQL with AutoIt!

Manic

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By zuladabef
      All my scripts were working fine and now I am getting this error.  How do I resolve it?  Which folder(s) do the DLLs need to be in?
      ! Dll not found or Call Dll error !  
    • By argumentum
      $sQueryUpdateTime = "select intUpdateTime from tblStudies " . $where . " ORDER BY intUpdateTime DESC limit 1"; $rs = mysqli_query($conn, $sQueryUpdateTime); $row = mysqli_fetch_assoc($rs); the above used to take 300+ ms. to query. Then I set it as index and takes 30 ms. Cool.
      $sQuery = "select * from tblStudies " . $where . " ORDER BY StudyDate DESC limit $offset,$rows"; // takes 30 ms. on the indexed int $sQuery = "select * from tblStudies " . $where . " ORDER BY StudyDate DESC , PatientName ASC limit $offset,$rows"; // takes 300 ms. due to "PatientName" been a text field, even as I did index it So my observation is that "PatientName" takes a long time to sort, even tho "$rows = 20". Sorting text in 20 rows should be fast.
      ..tho, I find that any 2nd argument in the ORDER BY is just slow.
      Is there a way to query this in a way to have a faster result back ?
      Thanks
      PS: added ADD INDEX `StudyDate_2` (`StudyDate`, `PatientBirthDate`) USING BTREE;  and searched by those two with not much speed change ( StudyDate and PatientBirthDate are integer ).
    • By argumentum
      I was thinking but I don't have the experience, so you may have the experience.
      I was thinking to chop a DB with 100.000 ( 20 columns ) in 10.000 DB chunks ( 10 DBs ) and query concurrently all of them to speed up a search, then add the results. Is that a sound idea ? Or will I run in trouble down the road. Should a DB better be keep in one piece ?
      The DB is now in MySQL. I wanna do all this chopping and use SQLite. 
      Thanks
      [solved]
    • By RAMzor
      Hello all!
      I got the Acroname Programmable USB Hub based on BrainStem platform. I will use it to manage ports and read current.
      They have development kit (BRAINSTEM DEVELOPMENT KIT) with examples for any languages like C#, C++, LabVIEW and python but no AutoIt.
      The kit include BrainStem2.dll (x32 and x64), BrainStem2_LabVIEW.dll, BrainStem2CLI.dll and many examples.
      Anyone used this dll and implemented it in AutoIt?
      Please share some example for Device Discovering, User LED Flashing or power enable/disable on port to start play with this HUB
      BrainStem Reference 
       
      BrainStem2 lib+example.7z USB HUB User Manual s79-usbhub-3p_v1.10_0.pdf
    • By matwachich
      Hi guys!
      A pretty simple UDF to convert HTML to PDF using wkHTMLtoPDF.
      It uses the C API of the tool (DLL), so no external process, no ActiveX or COM sh*t.
      See the example, and the documentation of wkHTMLtoPDF.
      Cheers
      https://github.com/matwachich/wkhtmltopdf-au3
×
×
  • Create New...