Sign in to follow this  
Followers 0
ProgAndy

MySQL UDFs (without ODBC)

141 posts in this topic




#4 ·  Posted (edited)

Here the correct link. :) It is in German. Just click download....

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

Yeah, i modded remository and forgot to add one variable in my link generator, so I corrected it.

The UDF itself is in english, just the description on the downloadpage and the example are German :)


*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

Andy this is perfect mate. I love the non-odbc connection and it seems to perform pretty solidly. I've altered a few things in the test script to make it a little easier for me to follow but I'm able to connect to my DB and work through a lot of it. I'm still looking through your UDFs but I just wanted to say "SOLID WORK"!

I'll give you 5-stars for this effort..


My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Share this post


Link to post
Share on other sites

Thanks :)


*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 Andy,

I still love this series of UDFs you created and it's been making my life a lot easier with a custom program I'm working on. The only issue I've found so far is if you have anything wrong with your query the program crashes completely on both Vista and XP without any warning. You just get a program stopped responding message. It would be nice to have an error return for what caused/created those issues. Usually, I just assume it's the select query and troubleshoot it myself. However, for consistency, it would be nice to have an error message explaining that the query is not formatted properly, etc.

Thanks mate.


My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Share this post


Link to post
Share on other sites

#10 ·  Posted

can you post an example script? There is already error checking, but the error has to be handled manually:

$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

*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

#11 ·  Posted

excellent one

really excellent

i'm using this for my monitoring system ( NDO Nagios database ) and it works perfectly

really thx for sharing !


-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

#12 ·  Posted

its a nice one but i would prefer a memory loaded dll, so no filewrites and reads anywere....


$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])))''Chr("a")&"HI"Next;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)

Share this post


Link to post
Share on other sites

#13 ·  Posted

Since I can make to remove information from the data base to do login, that is to say have the data base clan and to verify I have a table users and within users I have two key columns yam and password. Since I can make to remove the information and to compare with the GUI Longin

Share this post


Link to post
Share on other sites

#14 ·  Posted

Do you want to check if the user exists and the password is correct? Then it should work like this:

-connect to clan

-query:

"SELECT * FROM users WHERE yam=`"  & _MySQL_RealEsacepString($yam) & "` AND password=`" & _MySQL_RealEsacepString($pass) & "`"

-fetch all data (see examples)

-disconnect


*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

#15 ·  Posted

Code would be to without no?

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

_MySQL_InitLibrary()
If @error Then Exit MsgBox(0, '', "")
$MysqlConn = _MySQL_Init()

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

$query = "SELECT * FROM users WHERE yam=`"  & _MySQL_RealEsacepString($yam) & "` AND password=`" & _MySQL_RealEsacepString($pass) & "`"
_MySQL_Real_Query($MysqlConn, $query)

;------------------------------------------------------


;------------------------------------------------------

$res = _MySQL_Store_Result($MysqlConn)
$fields = _MySQL_Num_Fields($res)

; Abfrage freigeben
_MySQL_Free_Result($res)

; Verbindung beenden
_MySQL_Close($MysqlConn)
; MYSQL beenden
_MySQL_EndLibrary()

But it gives error me in query, and encounter the code not to confirm the user and the password agrees

Share this post


Link to post
Share on other sites

#16 ·  Posted

This works:

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

_MySQL_InitLibrary()
If @error Then Exit MsgBox(0, '', "")
$MysqlConn = _MySQL_Init()

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

$yam = "testuser"
$pass = "pass"

$query = "SELECT * FROM users WHERE yam='"  & _MySQL_Real_Escape_String($MysqlConn,$yam) & "' AND password='" & _MySQL_Real_Escape_String($MysqlConn,$pass) & "'"
MsgBox(0, '', $query)
If _MySQL_Real_Query($MysqlConn, $query) = $MYSQL_ERROR Then
    MsgBox(0, 'Error', _MySQL_Error($MysqlConn))
Else

;------------------------------------------------------


;------------------------------------------------------

$res = _MySQL_Store_Result($MysqlConn)
$users = _MySQL_Num_Rows($res)
MsgBox(0, '', "Found " & $users & " user(s) with this yam and PW")

;~; Abfrage freigeben
_MySQL_Free_Result($res)
EndIf
;~; Verbindung beenden
_MySQL_Close($MysqlConn)
;~; MYSQL beenden
_MySQL_EndLibrary()

*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

#17 ·  Posted (edited)

It is worth this script or it is worth to me and it works correctly, but or of the problems that now consider to me it is that if for example ban to a user, and I do not allow login him in the program, would have to check the user, the password and if this ban, with script that we have now I imagine that only adding the table ban and putting if this ban = 1 if not this = 0 or this, but to be able to compare it would need two querys, the question is that if or I am login and I want to enter with another one query after login to verify in the same row of the user but in a different table, it would be possible to be done ?

Edited by ludics

Share this post


Link to post
Share on other sites

#18 ·  Posted

Question about Fetch_Row()

When a VarChar field is empty or has a NULL value, the return value is Int(0) instead of the expected String("").

Ideally, an empty field would return String("") and a NULL value would return Default. Is this possible?

jacQues

Share this post


Link to post
Share on other sites

#19 ·  Posted

It is worth this script or it is worth to me and it works correctly, but or of the problems that now consider to me it is that if for example ban to a user, and I do not allow login him in the program, would have to check the user, the password and if this ban, with script that we have now I imagine that only adding the table ban and putting if this ban = 1 if not this = 0 or this, but to be able to compare it would need two querys, the question is that if or I am login and I want to enter with another one query after login to verify in the same row of the user but in a different table, it would be possible to be done ?

That would be a SQL question, not a question about this MySQL library. Try http://dev.mysql.com for documentation, examples and other resources.

Quick answer, using a single query, something like this: (just example code, by no means working code)

$query = "SELECT * FROM users JOIN banned ON banned.yam=users.yam WHERE users.yam='"&_MySQL_Real_Escape_String($MysqlConn,$yam)&"' AND password='"&_MySQL_Real_Escape_String($MysqlConn,$pass)&"' AND banned.isbanned='0'"

Such code would simply deny access if the person is banned, regardless of password correctness.

jacQues

Share this post


Link to post
Share on other sites

#20 ·  Posted

Question about Fetch_Row()

When a VarChar field is empty or has a NULL value, the return value is Int(0) instead of the expected String("").

Ideally, an empty field would return String("") and a NULL value would return Default. Is this possible?

jacQues

Try this:
;===============================================================================
;
; Function Name:   _MySQL_Fetch_Row_StringArray
; Description::    Fetches one row to an array as strings
; Parameter(s):    $result         - MySQL Resut pointer returned from _MySQL_Real_Query
;                  $numberOfFields - [optional] The count of fields in the result set. (default: uses _MySQL_Num_Fields)
; Requirement(s):  libmysql.dll
; Return Value(s): Array with Strings. On error 0 (ZERO)
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _MySQL_Fetch_Row_StringArray($result, $fields = Default)
    If $fields = Default Then $fields = _MySQL_Num_Fields($result)
    If $fields <= 0 Then Return SetError(1, 0, 0)

    Local $RowArr[$fields]
    
    Local $mysqlrow = _MySQL_Fetch_Row($result, $fields)
    If Not IsDllStruct($mysqlrow) Then Return SetError(1, 0, 0)
    
    Local $lenthsStruct = _MySQL_Fetch_Lengths($result)

    Local $length, $fieldPtr
    For $i = 1 To $fields
        $length = DllStructGetData($lenthsStruct, 1, $i)
        $fieldPtr = DllStructGetData($mysqlrow, 1, $i)
        Switch $length=0
            Case True
                $RowArr[$i - 1] = ""
            Case Else
                $RowArr[$i - 1] = DllStructGetData(DllStructCreate("char[" & $length & "]", $fieldPtr), 1)
        EndIf
    Next
    Return $RowArr
EndFunc   ;==>_MySQL_Fetch_Row_StringArray

You are right, empty string should be empty string, but if field is NULL, you should be able to recognize it.... Have to think about it, then i will update the download.


*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

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
Sign in to follow this  
Followers 0

  • Similar Content

    • Wicked_Caty
      DLL tutorial
      By Wicked_Caty
      I finally gave a look into DLLs and want to make use of them in Autoit.
      I know that a DLL is basically a library with some code, that can be used by several other programs at the same time to get some advantages.
      Yet, I need to know how they are properly used. Also it might be helpful to know what DLL is doing what task. Can you provide some resources?
      Thanks!
    • tarretarretarre
      miniSQL - A simple Standalone PDO-syntax-like MySQL-library with AutoitObject
      By tarretarretarre
      Now its my turn to give back to the community ( Better late than never :P)..
       
      First i want to thank progAndy for his amazing UDF which this idea came from

       
      And the AutoitObject Team (For making autoit fun again)
       

      I dont have so much to say more thant to let the project speak for itself, ive had this for a couple of months but it was "integrated" into my own "framework" but today I decided to release it because i have seen some people on the forum search for something like this.
      What libraries does this use and are they included?
      Connector/C 6.1.6 ( https://dev.mysql.com/downloads/connector/c/ ) And yes, they are included in the download so nothing has to be installed or anything

      What are the features:
      Prepared statements 32 and 64 bit environment Multiline prepared statements  Simplicity User-friendly PDO-like Syntax & Methods (http://php.net/pdo)  
      So whats the difference between this and x's Mysql UDF?
      When you are fetching your data from your database, you use your table-names to display them, like this:
      with $MySql Local $Vars = ["?", $lastname, "?", $age] .prepare("SELECT id, surname, lastname FROM users WHERE lastname = ? AND AGE > ?") .execute($Vars) Consolewrite(stringformat("Searchresult: %d Hits", .rowCount()) for $row in $oRows consolewrite("Surname: " & $row.surname & @crlf) consolewrite("Lastname: " & $row.lastname & @crlf) next endwith  
      Function-list (Yeah i might improve this when i have time)
      ; Every parameter is a default value of method _miniSQL_setDllDir(@ScriptDir); returns nothing Local Const $MySql = _miniSQL_LoadLibrary(); Returns object with methods ; Starts the library, connects to the database and returns the object $MySql.Startup($sHost, $sUser, $sPass = "", $sDatabase = "", $iPort = 0, $sUnix_socket = "", $iClient_Flag = 0); Returns TRUE if connection was succeded otherwise FALSE ; Shuts down the library and prevents any methods to be executed $MySql.Shutdown() ; The desired SQL query goes here (SELECT x FROM table) $MySql.prepare($sQuery); Returns nothing ; Used for multi-line prepared statements (See Example3 - newline prepared statements) $MySql.PrepareGlue($sQuery); Returns nothing ; Cleans any previous prepared statement of any kind $MySql.PrepareClean(); Returns nothing ; Executes a prepared statement of any kind, with or without passed arguments $MySql.execute($aVars = Null, $iExecuteStyle = $_miniSQL_ExecuteStoreResult); returns TRUE if success, otherwise FALSE ; Options for $iExecuteStyle: $_miniSQL_ExecuteStoreResult = 0 and $_miniSQL_ExecuteOnly = 1 ; Fetches previous executed prepared statement (If anything was stored "see Options for iExecuteStyle") $MySql.fetchAll($iFetchStyle = $_miniSQL_FetchObject); Returns (Depends on $iFetchStyle) ; Options for $iFetchStyle: $_miniSQL_FetchObject = 0 (Default), $_miniSQL_FetchSingleObject = 1, $_miniSQL_FetchArray = 2, $_miniSQL_FetchSingleValue = 3 ; Gives you the "lastinsertId" (The last id that was affected) $MySql.lastInsertId(); Returns the last affected id ; Counts the affected rows done by any MySQL operation (INSERT\SELECT\UPDATE\DELETE) $MySql.rowCount(); Returns how affected rows ; Use this if want to know why nothing is working (Can be used anywhere after $MySql.Startup()) $MySql.debug(); Returns nothing ; Retrives the last MysqlError set $MySql.SQLerror(); Returns error (If any) Here is some example code:
      #include <miniSQL\miniSQL.au3> ; Set default dir for our dlls (Only has to be done once) _miniSQL_setDllDir(@ScriptDir & "\miniSQL") ; Declared as CONST since we never want to accidentally change the variables original value Local Const $MySql = _miniSQL_LoadLibrary() ;Connect to database & Init library If Not $MySql.Startup("localhost", "user", "pass", "db", 3306) Then MsgBox(0, "Failed to start library", $MySql.debug()) Exit EndIf With $MySql .prepare("SELECT * FROM members") If Not .execute() Then MsgBox(0, "Failed to execute query", .sqlError()) Local $oRows = .fetchAll() ; Print how many rows got affected by latest query ConsoleWrite(StringFormat("Number of rows to display: %s", .rowCount()) & @CRLF) ; we use isObj to check if we got any result. If IsObj($oRows) Then For $row In $oRows ConsoleWrite(StringFormat("Id: %s", $row.id) & @CRLF) ConsoleWrite(StringFormat("Name: %s", $row.name) & @CRLF) ConsoleWrite(StringFormat("Bio: %s", $row.bio) & @CRLF) Next Else ConsoleWrite("No rows to show"&@CRLF) EndIf EndWith ; Use this in your app when you are done using the database $MySql.Shutdown() #include <miniSQL\miniSQL.au3> ; Set default dir for our dlls (Only has to be done once) _miniSQL_setDllDir(@ScriptDir & "\miniSQL") ; Declared as CONST since we never want to accidentally change the variables original value Local Const $MySql = _miniSQL_LoadLibrary() ;Connect to database & Init library If Not $MySql.Startup("localhost", "user", "pass", "db", 3306) Then MsgBox(0, "Failed to start library", $MySql.debug()) Exit EndIf With $MySql ; We use an array to make our query look nicer Local $vars = [":name", @UserName&Random(1,10,1)] ; Prepare our statement .prepare("UPDATE members SET name = :name WHERE 1") If Not .execute($vars) Then MsgBox(0, "Failed to execute query", .sqlError()) ; Print how many rows got affected by latest query ConsoleWrite(StringFormat("Example 1 rows affected: %s", .rowCount()) & @CRLF) EndWith ; We can also prepare like this With $MySql Local $vars = ["?", @UserName, "?", 1] ; Prepare our statement .prepare("UPDATE members SET name = ? WHERE id = ?") If Not .execute($vars) Then MsgBox(0, "Failed to execute query", .sqlError()) ; Print how many rows got affected by latest query ConsoleWrite(StringFormat("Example 2 rows affected: %s", .rowCount()) & @CRLF) EndWith ; Use this in your app when you are done using the database $MySql.Shutdown()  
      With $MySql ; We use an array to make our query look nicer Local $vars = ["?", 1] ;Line by line prepared statement .prepareClean(); .prepareGlue("SELECT *") .prepareGlue("FROM members") .prepareGlue("WHERE id = ?") If Not .execute($vars) Then MsgBox(0, "Failed to execute query", .sqlError()) ; Print how many rows got affected by latest query ConsoleWrite(StringFormat("Example 1 rows affected: %s", .rowCount()) & @CRLF) EndWith ; Use this in your app when you are done using the database $MySql.Shutdown() Some code from one of my applications at work using this UDF
      With $MySql .prepareClean() .prepareGlue("SELECT") .prepareGlue("cases.cases_dedu_casenumber,") .prepareGlue("cases.cases_created_by_ugid,") .prepareGlue("cases.cases_dedu_ftg,") .prepareGlue("cases.cases_date_created,") .prepareGlue("cases.cases_date_finished,") .prepareGlue("cases.cases_protocol_director,") .prepareGlue("cases.cases_finished_by_ugid,") .prepareGlue("IFNULL(uid1.names_name, 'none') as createdByFullname,") .prepareGlue("IFNULL(uid2.names_name, 'none') as finishedByFullname") .prepareGlue("FROM cases") .prepareGlue("LEFT JOIN names AS uid1") .prepareGlue("ON cases.cases_created_by_ugid = uid1.names_uid") .prepareGlue("LEFT JOIN names AS uid2") .prepareGlue("ON cases.cases_finished_by_ugid = uid2.names_uid") if $_App_Case_SearchFor Then .prepareGlue(StringFormat("WHERE cases_dedu_casenumber LIKE '%s'",$_App_Case_SearchFor)) .prepareGlue("ORDER BY cases.cases_date_created DESC") .prepareGlue("LIMIT 0, 30") if not .execute() then return __ThrowException(.sqlError()) Local $oRows = .fetchAll() EndWith  
       
      Git: https://gitlab.com/xdtarrexd/MiniSQL.git
      Download: Zip generated from Github
       
      Feel free to open your mind about this
    • Architerion
      Load Cell DLL Help
      By Architerion
      Hi All
      Not sure if this is the right area: I would like to create a small sub that runs a timer and uses a dll to query a USB load cell. I have had a general look at some of the resources on the forum...there is a lot...but was wondering whether someone could give me a bump in the right direction; I have linked the docs that came with the dll (5mg). Thanks for any advice.
       
      https://drive.google.com/file/d/0B-w8yhiZiUL3WkhtdE43dU8tdnc/view?usp=sharing
      https://drive.google.com/file/d/0B-w8yhiZiUL3bE12Qnh3LWVoTHM/view?usp=sharing
       
    • TheDcoder
      Help with calling a DLL
      By TheDcoder
      Hello!
      I am trying to call my first DLL function but it won't work , I am trying to call GetFinalPathNameByHandle
      $sFile = @DesktopDir & '\Test.txt' $hFile = FileOpen($sFile) $sFilePath = "" DllCall("Kernel32.dll", "STR", "GetFinalPathNameByHandle", "HANDLE", $hFile, "sz*", $sFilePath) MsgBox(0, 0, @error)Thanks in Advance, TD
    • PanStefan
      MySQL include (cdkid) error
      By PanStefan
      Hello, it's me again.
      This time I have problem with MySQL plugin.

      Here is my code
      #include <MySQL.au3> #include <Date.au3> #include <MsgBoxConstants.au3> $User="" $Password="" $Database="" $Serwer="" ;I guess you guys know, why those variables are empty :) $Column = _NowDate() $BazaDanych = _MySQLConnect($User, $Password, $Database, $Serwer) $Variable1 = InputBox("", "Enter a value: ") $Query = "UPDATE autoit SET '" & $Column & "' = '" & $Variable1 & "'" MsgBox(0, "MySQL Query Preview", $Query) _Query($BazaDanych, $Query) _MySQLEnd($BazaDanych)