Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/02/2013 in all areas

  1. 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 If you do not need the power of these UDFs and you simple want to use basic SQL commands, then have a look at not included: MySQL_Connect - This function is deprecated. Use _MySQL_Real_Connect instead. MySQL_Create_DB - This function is deprecated. Use mysql_query() to issue an SQL CREATE DATABASE statement instead. MySQL_Drop_DB - This function is deprecated. Use mysql_query() to issue an SQL DROP DATABASE statement instead. MySQL_Escape_String - You should use _mysql_real_escape_string() instead! MySQL_Kill - This function is deprecated. Use mysql_real_query() to issue an SQL KILL statement instead mysql_library_end - Called by _MySQL_EndLibrary. mysql_library_init - Called by _MySQL_InitLibrary. 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: (including x86 and x64)</array.au3>
    1 point
  2. This function will calculate the Finonacci number based on a decimal value. Function: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Fibonacci ; Description ...: Calculate the Fibonacci number of a decimal value. ; Syntax ........: _Fibonacci($iIterations) ; Parameters ....: $iIterations - An integer value to iterate to. ; Return values .: Success - Fibonacci value ; Author ........: guinness & UEZ ; Link ..........: C++ example: https://en.wikipedia.org/wiki/Functional_programming#Coding_styles ; Example .......: Yes ; =============================================================================================================================== Func _Fibonacci($iIterations) $iIterations = Int($iIterations) Local $iFirst = 0, $iSecond = 1, $iSum = 0 If $iIterations > 92 Then $iSecond = 1.0 EndIf For $i = 0 To ($iIterations - 1) $iSum = $iFirst + $iSecond $iFirst = $iSecond $iSecond = $iSum Next Return $iFirst EndFunc ;==>_FibonacciFunction V3.9.9.4+ ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Fibonacci ; Description ...: Calculate the Fibonacci number of a decimal value. ; Syntax ........: _Fibonacci($iIterations) ; Parameters ....: $iIterations - An integer value to iterate to. ; Return values .: Success - Fibonacci value ; Author ........: guinness & trancexx ; Link ..........: C++ example: https://en.wikipedia.org/wiki/Functional_programming#Coding_styles ; Example .......: Yes ; =============================================================================================================================== Func _Fibonacci($iIterations) $iIterations = Int($iIterations) Local $iFirst = 0, $iSecond = ($iIterations > 92) ? 1.0 : 1, $iSum = 0 For $i = 0 To ($iIterations - 1) $iSum = $iFirst + $iSecond $iFirst = $iSecond $iSecond = $iSum Next Return $iFirst EndFunc ;==>_FibonacciExample use of Function: For $i = 0 To 20 ConsoleWrite($i & ' >> ' & _Fibonacci($i) & @CRLF) Next
    1 point
  3. OK, seems who ever said that must have seen at some point but missed the part about it being fixed.
    1 point
  4. It's nothing to do with speed, just ease of readability and the unnecessary use of calling a secondary function for information you already know.
    1 point
  5. Wouldn't the third example above be practically the same as the example above using $a = UBound($array) - 1? Again, in testing I don't see any speed difference in doing it in any of the 3 methods, they're all statistically the same in repeated tests.
    1 point
  6. Also for the sake of learning (I presume this is what you want?) your example is declaring the variable in Global scope when it should be Local. Local $aProblems[99] ; Jay-Z Array For $i = 0 To UBound($aProblems) - 1 ; Enumerate through the array. Next This is valid use, as the variable is use other than its current scope. Global $aProblems[99] ; Jay-Z Array For $i = 0 To UBound($aProblems) - 1 ; Enumerate through the array. Next Func SomeFunc() For $i = 0 To UBound($aProblems) - 1 ; Enumerate through the array. Next EndFunc ;==>SomeFunc Func AnotherFunc() $aProblems = 0 EndFunc ;==>AnotherFunc Local $aProblems[99] = [98] ; Jay-Z Array For $i = 1 To $aProblems[0] ; If I know the size of the array beforehand, I like to use the 0th index as the count. ; This theory can also be applied to arrays which are dynamic too. ; Enumerate through the array. Next
    1 point
  7. BitByteBit, guinness is correct - in your first example, the loop bound is only evaluated once: as you enter the loop. You can modify the loop counter programatically by changing the value of $i inside the loop, but changing the size of the array within the loop will not affect the intially set limit. That is why when you are changing the size of the array (deleting unnecessary elements for example) you must always start at the bottom of the array and work up using Step -1. M23
    1 point
  8. Yes, turning left 3 times to turn right! kylomas
    1 point
  9. You also need a space before the /K
    1 point
  10. You forgot the space between the /k and the single quote. RunWait (@ComSpec &'/k' & $cmd)should beRunWait (@ComSpec &'/k ' & $cmd)
    1 point
  11. Imbuter2000, I really would not worry about it too much. The nature of AutoIt makes it difficult to avoid Global variables - so if you feel the need to use them then do so. Personally I would rather have legible code with some sensible Global variables than a psuedo-elegant web of parameters passed between functions - remember you are going to have to maintain this code in the future. Just try and avoid making every variable in the script Global in scope - that is not the way to go. M23
    1 point
  12. 1 point
  13. Yes, it is possible . Take a look to help file; EnvGet, EnvSet & EnvUpdate. Edit: Well, using EnvSet to set an environment variable will made this "add" available to programs that AutoIt spawns (Run, RunWait). Once AutoIt closes, the variables will cease to exist. So, if you want to make the change permanent could use something like this: $key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" $val = "PATH" $PATH = RegRead($key, $val) $sAddThisPath = "C:\my new path\" $PATH = $PATH & ";" & $sAddThisPath RegWrite($key,$val,"REG_EXPAND_SZ",$PATH) EnvUpdate() Cheers, sahsanu
    1 point
×
×
  • Create New...