Iczer Posted November 6, 2015 Share Posted November 6, 2015 Trac dont like me anymore... i post here:in answer to Ticket #3149 (Add new functions to SQLite UDF) Melba23That code is not the current _SQLite_GetTable2d function - and where is this new $iReturnArray parameter? Or do you expect someone else to do all the work?OKoriginal functions from 3.3.14.xexpandcollapse popup; #FUNCTION# ==================================================================================================================== ; Author ........: piccaso (Fida Florian), blink314 ; Modified.......: jchd, Iczer ; ;$iRetOption = 0 - default ;$iRetOption = 1 - 1-based array ;$iRetOption = 2 - 0-based array ; =============================================================================================================================== Func _SQLite_GetTable2d_EX($hDB, $sSQL, ByRef $aResult, ByRef $iRows, ByRef $iColumns, $iCharSize = -1, $bSwichDimensions = False, $iRetOption = 0) If __SQLite_hChk($hDB, 1) Then Return SetError(@error, 0, $SQLITE_MISUSE) If $iCharSize = "" Or $iCharSize < 1 Or $iCharSize = Default Then $iCharSize = -1 $iRetOption = (StringRegExp($iRetOption,"\A[012]\z",0))?(Number($iRetOption)):(0);<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $sCallBack = "", $bCallBack = False If IsString($aResult) Then If StringLeft($aResult, 16) = "SQLITE_CALLBACK:" Then $sCallBack = StringTrimLeft($aResult, 16) $bCallBack = True EndIf EndIf $aResult = '' If $bSwichDimensions = Default Then $bSwichDimensions = False Local $hQuery Local $r = _SQLite_Query($hDB, $sSQL, $hQuery) If @error Then Return SetError(2, @error, $r) If $r <> $SQLITE_OK Then __SQLite_ReportError($hDB, "_SQLite_GetTable2d", $sSQL) _SQLite_QueryFinalize($hQuery) Return SetError(-1, 0, $r) EndIf $iRows = 0 Local $iRval_Step, $iError While True $iRval_Step = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_step", "ptr", $hQuery) If @error Then $iError = @error _SQLite_QueryFinalize($hQuery) Return SetError(3, $iError, $SQLITE_MISUSE) ; DllCall error EndIf Switch $iRval_Step[0] Case $SQLITE_ROW $iRows += 1 Case $SQLITE_DONE ExitLoop Case Else _SQLite_QueryFinalize($hQuery) Return SetError(3, $iError, $iRval_Step[0]) EndSwitch WEnd Local $iRet = _SQLite_QueryReset($hQuery) If @error Then $iError = @error _SQLite_QueryFinalize($hQuery) Return SetError(4, $iError, $iRet) EndIf Local $aDataRow $r = _SQLite_FetchNames($hQuery, $aDataRow) If @error Then $iError = @error _SQLite_QueryFinalize($hQuery) Return SetError(5, $iError, $r) EndIf $iColumns = UBound($aDataRow) If $iColumns <= 0 Then _SQLite_QueryFinalize($hQuery) Return SetError(-1, 0, $SQLITE_DONE) EndIf $iRowsActual = ($iRetOption = 2)?($iRows):($iRows + 1);<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $iRowsStart = ($iRetOption = 2)?(0):(1);<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If Not $bCallBack Then If $bSwichDimensions Then Dim $aResult[$iColumns][$iRowsActual];<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If $iRetOption = 0 Then;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< For $i = 0 To $iColumns - 1 If $iCharSize > 0 Then $aDataRow[$i] = StringLeft($aDataRow[$i], $iCharSize) EndIf $aResult[$i][0] = $aDataRow[$i] Next EndIf;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Else Dim $aResult[$iRowsActual][$iColumns];<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If $iRetOption = 0 Then;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< For $i = 0 To $iColumns - 1 If $iCharSize > 0 Then $aDataRow[$i] = StringLeft($aDataRow[$i], $iCharSize) EndIf $aResult[0][$i] = $aDataRow[$i] Next EndIf;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf Else Local $iCbRval $iCbRval = Call($sCallBack, $aDataRow) If $iCbRval = $SQLITE_ABORT Or $iCbRval = $SQLITE_INTERRUPT Or @error Then $iError = @error _SQLite_QueryFinalize($hQuery) Return SetError(7, $iError, $iCbRval) EndIf EndIf If $iRows > 0 Then For $i = $iRowsStart To $iRowsActual - 1;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $r = _SQLite_FetchData($hQuery, $aDataRow, 0, 0, $iColumns) If @error Then $iError = @error _SQLite_QueryFinalize($hQuery) Return SetError(6, $iError, $r) EndIf If $bCallBack Then $iCbRval = Call($sCallBack, $aDataRow) If $iCbRval = $SQLITE_ABORT Or $iCbRval = $SQLITE_INTERRUPT Or @error Then $iError = @error _SQLite_QueryFinalize($hQuery) Return SetError(7, $iError, $iCbRval) EndIf Else For $j = 0 To $iColumns - 1 If $iCharSize > 0 Then $aDataRow[$j] = StringLeft($aDataRow[$j], $iCharSize) EndIf If $bSwichDimensions Then $aResult[$j][$i] = $aDataRow[$j] Else $aResult[$i][$j] = $aDataRow[$j] EndIf Next EndIf Next EndIf If $iRetOption = 1 Then $aResult[0][0] = $iRowsActual-1;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Return (_SQLite_QueryFinalize($hQuery)) EndFunc ;==>_SQLite_GetTable2d ; #FUNCTION# ==================================================================================================================== ; Author ........: piccaso (Fida Florian) ; Modified.......: jchd, Iczer ; ;$iRetOption = 0 - default ;$iRetOption = 1 - 1-based array ;$iRetOption = 2 - 0-based array ; =============================================================================================================================== Func _SQLite_GetTable_EX($hDB, $sSQL, ByRef $aResult, ByRef $iRows, ByRef $iColumns, $iCharSize = -1, $iRetOption = 0) $aResult = '' If __SQLite_hChk($hDB, 1) Then Return SetError(@error, 0, $SQLITE_MISUSE) If $iCharSize = "" Or $iCharSize < 1 Or $iCharSize = Default Then $iCharSize = -1 $iRetOption = (StringRegExp($iRetOption,"\A[012]\z",0))?(Number($iRetOption)):(0);<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; see comments in _SQLite_GetTable2d Local $hQuery Local $r = _SQLite_Query($hDB, $sSQL, $hQuery) If @error Then Return SetError(2, @error, $r) ; we need column count and names Local $aDataRow $r = _SQLite_FetchNames($hQuery, $aDataRow) Local $iError = @error If $iError Then _SQLite_QueryFinalize($hQuery) Return SetError(3, $iError, $r) EndIf $iColumns = UBound($aDataRow) Local Const $iRowsIncr = 64 ; initially allocate 64 datarows then grow by 4/3 of row count $iRows = 0 ; actual number of data rows Local $iAllocRows = $iRowsIncr ; number of allocated data rows Local $idx;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Switch $iRetOption;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case 0 Dim $aResult[($iAllocRows + 1) * $iColumns + 1] Case 1 Dim $aResult[$iAllocRows * $iColumns + 1] $idx = 0 Case 2 Dim $aResult[$iAllocRows * $iColumns] $idx = -1 EndSwitch;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If $iRetOption = 0 Then;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< For $idx = 0 To $iColumns - 1 If $iCharSize > 0 Then $aDataRow[$idx] = StringLeft($aDataRow[$idx], $iCharSize) EndIf $aResult[$idx + 1] = $aDataRow[$idx] Next EndIf;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< While 1 $r = _SQLite_FetchData($hQuery, $aDataRow, 0, 0, $iColumns) $iError = @error Switch $r Case $SQLITE_OK $iRows += 1 If $iRows = $iAllocRows Then $iAllocRows = Round($iAllocRows * 4 / 3) Switch $iRetOption;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case 0 ReDim $aResult[($iAllocRows + 1) * $iColumns + 1] Case 1 ReDim $aResult[$iAllocRows * $iColumns + 1] Case 2 ReDim $aResult[$iAllocRows * $iColumns] EndSwitch;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf For $j = 0 To $iColumns - 1 If $iCharSize > 0 Then $aDataRow[$j] = StringLeft($aDataRow[$j], $iCharSize) EndIf $idx += 1 $aResult[$idx] = $aDataRow[$j] Next Case $SQLITE_DONE ExitLoop Case Else $aResult = '' _SQLite_QueryFinalize($hQuery) Return SetError(4, $iError, $r) EndSwitch WEnd Switch $iRetOption;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case 0 $aResult[0] = ($iRows + 1) * $iColumns ReDim $aResult[$aResult[0] + 1] Case 1 $aResult[0] = $iRows * $iColumns ReDim $aResult[$aResult[0] + 1] Case 2 ReDim $aResult[$iRows * $iColumns] EndSwitch;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Return ($SQLITE_OK) EndFunc ;==>_SQLite_GetTable Link to comment Share on other sites More sharing options...
jchd Posted November 7, 2015 Share Posted November 7, 2015 NO, please.No 1-based arrays anymore! This nonsense is already plaging enough UDFs. Skysnake and minxomat 2 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Iczer Posted November 7, 2015 Author Share Posted November 7, 2015 nonsense? plaguing? Why this reaction? Any serious base behind it?For me - it pretty useful, and faster than always use Ubound() plus variableAlso - “Let hundreds of flowers blossom and hundreds of schools of thought contend" (百花齐放,百家争鸣). Link to comment Share on other sites More sharing options...
BrewManNH Posted November 7, 2015 Share Posted November 7, 2015 You can always transform the array returned to be one based yourself,it's not that hard. In fact it's extremely easy as your code demonstrates, but it would eat up some processing time, which is why 1 based arrays are not a solution to your problem.I don't see how creating the array inside the function, with a count in 0, is any quicker at all, compared to doing one call to UBound and getting the count from it. Skysnake 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now