Leaderboard
Popular Content
Showing content with the highest reputation on 01/16/2024 in all areas
-
SQLite Foreign Keys
argumentum reacted to Andreik for a topic
Since foreign keys are supported by default by pretty much all important relational database engines it would be nice to have it by default in SQLite as well. SQLite introduced support for foreign key constraints since SQLite v.3.6.19 but you have to manually enable foreign keys support at runtime. I know it's just a single line of code but should we consider to add this by default when _SQLite_Open() it's called? It might be a parameter as such: Func _SQLite_Open($sDatabase_Filename = Default, $iAccessMode = Default, $iEncoding = Default, $bFKEnable = True) If Not $__g_hDll_SQLite Then Return SetError(3, $SQLITE_MISUSE, 0) If $sDatabase_Filename = Default Or Not IsString($sDatabase_Filename) Then $sDatabase_Filename = ":memory:" Local $tFilename = __SQLite_StringToUtf8Struct($sDatabase_Filename) If @error Then Return SetError(2, @error, 0) If $iAccessMode = Default Then $iAccessMode = BitOR($SQLITE_OPEN_READWRITE, $SQLITE_OPEN_CREATE) Local $bOldBase = FileExists($sDatabase_Filename) ; encoding cannot be changed if base already exists If $iEncoding = Default Then $iEncoding = $SQLITE_ENCODING_UTF8 EndIf Local $avRval = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_open_v2", "struct*", $tFilename, _ ; UTF-8 Database filename "ptr*", 0, _ ; OUT: SQLite db handle "int", $iAccessMode, _ ; database access mode "ptr", 0) If @error Then Return SetError(1, @error, 0) ; DllCall error If $avRval[0] <> $SQLITE_OK Then __SQLite_ReportError($avRval[2], "_SQLite_Open") _SQLite_Close($avRval[2]) Return SetError(-1, $avRval[0], 0) EndIf $__g_hDB_SQLite = $avRval[2] __SQLite_hAdd($__g_ahDBs_SQLite, $avRval[2]) If Not $bOldBase Then Local $aEncoding[3] = ["8", "16", "16be"] _SQLite_Exec($avRval[2], 'PRAGMA encoding="UTF-' & $aEncoding[$iEncoding] & '";') EndIf If $bFKEnable Then _SQLite_Exec($avRval[2], 'PRAGMA foreign_keys = ON;') ; <<< --- added just this line to original _SQLite_Open() Return SetExtended($avRval[0], $avRval[2]) EndFunc ;==>_SQLite_Open If we really want to stick with the previous behavior of _SQLite_Open() then $bFKEnable can be set as False by default. Or we can add to UDF a new function like below to enable/disable foreign keys, but for me it makes more sense to enable the support when connection starts and you can disable support with _SQLite_Exec(). Func _SQLite_FK_Enable($hDB = Default, $bFKEnable = True) If __SQLite_hChk($hDB, 1) Then Return SetError(@error, 0, $SQLITE_MISUSE) If _SQLite_Exec($hDB, 'PRAGMA foreign_keys = ' & ($bFKEnable ? 'ON' : 'OFF') & ';') == $SQLITE_OK Then Return SetError(0, 0, $bFKEnable) Else Return SetError(2, 0, Null) EndIf EndFunc ;==>_SQLite_FK_Enable Thoughts on this?1 point -
Have you tried using the forum's Search feature? I know there's at least one UDF that adds joystick support.1 point
-
Antony72, I have run into this problem before - MS likes to give you the entire width of the ListView when you ask for the data of the 0 column. A workaround is to ask for the column width directly: $W = _GUICtrlListView_GetColumnWidth($hLV, $iCol) That solves the problem for me. M231 point
-
Outline in letters using GDI
Belini reacted to DutchCoder for a topic
Func _CreateLabel($_text, $_x, $_y, $_w = Default, $_h = Default, $_style = Default, $_fgcol = Default, $_bkcol = 0) Local $_d[4][2] = [[0, -1], [0, 1], [-1, 0], [1, 0]] For $_z = 0 To 3 GUICtrlCreateLabel($_text, $_x + $_d[$_z][0], $_y + $_d[$_z][1], $_w, $_h, $_style) GUICtrlSetColor(-1, $_bkcol) GUICtrlSetBkColor(-1, -2) Next $_label = GUICtrlCreateLabel($_text, $_x, $_y, $_w, $_h, $_style) GUICtrlSetColor(-1, $_fgcol) GUICtrlSetBkColor(-1, -2) Return $_label EndFunc Func _SetLabelData($_handle, $_data) For $_z = 0 To 4 GUICtrlSetData($_handle - $_z, $_data) Next EndFunc Simple solution as replacement for your GUICtrlCreateLabel() and GUICtrlSetData()1 point -
hi forum peoples for people that are using dBaseIII and dBaseIV database files i want to share my dbase dll + udf that i wrote for one of my projects the dll supports; open/create/read/write dbaseIII dbf files open/create/read/write dBaseIV dbf files open/create/read/write dbaseIII dbt memo files open/create/read/write dBaseIV dbt memo files most basic functions are in the dll more functions wil be added when needed dll ,udf and several samples are included in zipfile Have fun Jpam update; udf has now standard function headers changed Opt("OnExitFunc", "Close_DLL") to OnAutoItExitRegister("Close_DLL") update 02-01-2016: added fast powerfull case-insensitive search() function to dll with wildcard support update 09-01-2016: added foxpro 2.x and visual foxpro read support added foxpro 2.x fpt memo read support added visual foxpro memo read support dbasedll.zip1 point
-
dBase udf and dll
andrewGo reacted to pixelsearch for a topic
@Holmesware Unfortunately OP didn't show for years and as his dll code has been kept secret... Anyway, I tried the following and it seems to work fine, without calling his Search() function (which accepts only -1 as third parameter as you noticed, -1 means search in any column) but sometimes (many times !) we would like to search only in one column and return the rows matching that column. To achieve this, I commented the following lines in OP's file Search.au3 : ;~ $Array = DllStructCreate("DWORD[1000]") ; 1000 rows returned (max) in my case ;~ $recCnt = Search($hDbf, "*4.9400", -1, DllStructGetPtr($Array), DllStructGetSize($Array)) ;~ If $recCnt >0 Then ;~ $recNr = 1 ;~ $fldNr = 0 ;~ $index = 0 ;~ $subitem = 0 ;~ _GUICtrlListView_BeginUpdate($g_idListView) ;~ Do ;~ $rec = GetSubRecord($hDbf, DllStructGetData($Array,1,$recNr), $fldNr) ;~ GUICtrlCreateListViewItem($rec, $g_idListView) ;~ Do ;~ $rec = GetSubRecord($hDbf, DllStructGetData($Array,1,$recNr), $fldNr) ;~ _GUICtrlListView_SetItem($g_idListView, $rec, $index, $subitem) ;~ $fldNr += 1 ;~ $subitem += 1 ;~ Until $fldNr = $fldCnt ;~ $recNr += 1 ;~ $fldNr = 0 ;~ $index += 1 ;~ $subitem = 0 ;~ Until $recCnt == $index ;~ _GUICtrlListView_EndUpdate($g_idListView) ;~ EndIf And placed these lines instead : ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Local $fldNr = 0 ; 1st column = 0 Local $vSearch = 1000.55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Local $iIndex = - 1 ; keep it always - 1 For $i = 0 To GetRecordCount($hDbf) - 1 If StringInStr(GetSubRecord($hDbf, $i, $fldNr), $vSearch) > 0 Then $iIndex += 1 ; 0+ (first row got index 0) If $iIndex = 0 Then _GUICtrlListView_BeginUpdate($g_idListView) GUICtrlCreateListViewItem("", $g_idListView) For $j = 0 To $fldCnt - 1 _GUICtrlListView_SetItem($g_idListView, GetSubRecord($hDbf, $i, $j), $iIndex, $j) Next EndIf Next If $iIndex > -1 Then _GUICtrlListView_EndUpdate($g_idListView) The 2 lines where you indicate the searched column and what you're searching for are these ones : ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Local $fldNr = 0 ; 1st column = 0 Local $vSearch = 1000.55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Now in case you want, from time to time, search again in any column, then you could rework the whole code and, when $fldNr = - 1, switch back to OP's code etc... Timers showed same speed as OP's Search function in the dll (based on a dbf of 1000 rows and 64 cols) Good luck1 point -
Just found out where this might apply! The _sql library that we use (from Chris Lambert) apparently brings in NULLS as "Default". I was trying to detect the NULL values using If $varName = "" Then ... EndIf Which was not working, so now I do If IsKeyword($varName) OR $varName = "" Then ... EndIf Which works as it should. Just thought I'd throw this note in here for anyone else using the _sql library and trying to detect empty (NULL) values.1 point
-
DBF-UDF - dBase database read and write with DLL
andrewGo reacted to boomingranny for a topic
For anyone else that needs this: This is the link to the attachment in the german forum. https://autoit.de/wcf/index.php?attachment/81316-dbf-rar/ I have also attached it to this post DBF.rar1 point -
Hello. Here you have. #include <WinAPIProc.au3> #include <WinAPI.au3> Opt("MustDeclareVars", 1) #RequireAdmin Global Const $OWNER_SECURITY_INFORMATION = 0x1 Global Const $GROUP_SECURITY_INFORMATION = 0x2 Global Const $DACL_SECURITY_INFORMATION = 0x4 Global Const $FILE_GENERIC_READ = 0x120089 ;STANDARD_RIGHTS_READ Or FILE_READ_DATA Or FILE_READ_ATTRIBUTES Or _FILE_READ_EA Or SYNCHRONIZE Global Const $FILE_GENERIC_WRITE = 0x120116 ;STANDARD_RIGHTS_WRITE Or FILE_WRITE_DATA Or FILE_WRITE_ATTRIBUTES Or _FILE_WRITE_EA Or FILE_APPEND_DATA Or SYNCHRONIZE Global Const $FILE_GENERIC_EXECUTE = 0x1200A0 ;STANDARD_RIGHTS_EXECUTE Or FILE_READ_ATTRIBUTES Or FILE_EXECUTE Or SYNCHRONIZE Global Const $FILE_ALL_ACCESS = 0x1F01FF ;STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &H1FF Global Const $sTag_GENERIC_MAPPING = "dword GenericRead;dword GenericWrite;dword GenericExecute;dword GenericAll;" If _CanAccessFolder("C:\System Volume Information", $GENERIC_WRITE) Then MsgBox(0, ":)", "I can Write...") Else MsgBox(0, ":(", "I can't Write...") EndIf If _CanAccessFolder("C:\", $GENERIC_WRITE) Then MsgBox(0, ":)", "I can Write...") Else MsgBox(0, ":(", "I can't Write...") EndIf Func _CanAccessFolder($sDir, $genericAccessRights) Local $bRet = False Local $tSecurityDescriptor = _GetSecurityDescriptor($sDir) ConsoleWrite("$tSecurityDescriptor: " & DllStructGetData($tSecurityDescriptor, 1) & @CRLF) Local $hToken = _WinAPI_OpenProcessToken(BitOR($TOKEN_IMPERSONATE, $TOKEN_QUERY, $TOKEN_DUPLICATE, $STANDARD_RIGHTS_READ)) ConsoleWrite("$hToken: " & $hToken & @CRLF) Local $hImpersonatedToken = _WinAPI_DuplicateTokenEx($hToken, 0, $SECURITYIMPERSONATION, $TOKENIMPERSONATION) ConsoleWrite("$hImpersonatedToken: " & $hImpersonatedToken & @CRLF) Local $tmapping = DllStructCreate($sTag_GENERIC_MAPPING) $tmapping.GenericRead = $FILE_GENERIC_READ $tmapping.GenericWrite = $FILE_GENERIC_WRITE $tmapping.GenericExecute = $FILE_GENERIC_EXECUTE $tmapping.GenericAll = $FILE_ALL_ACCESS _MapGenericMask($tmapping, $genericAccessRights) ConsoleWrite("$genericAccessRights: " & $genericAccessRights & @CRLF) Local $tprivilege_set = DllStructCreate("dword;dword;dword;dword;dword") Local $aRet = DllCall("Advapi32.dll", "bool", "AccessCheck", "ptr", DllStructGetPtr($tSecurityDescriptor), "handle", $hImpersonatedToken, "dword", $genericAccessRights, _ "ptr", DllStructGetPtr($tmapping), "ptr", DllStructGetPtr($tprivilege_set), "dword*", DllStructGetSize($tprivilege_set), "dword*", 0, "bool*", 0) $bRet = $aRet[8] If $hImpersonatedToken Then _WinAPI_CloseHandle($hImpersonatedToken) If $hToken Then _WinAPI_CloseHandle($hToken) Return $bRet EndFunc ;==>_CanAccessFolder Func _GetSecurityDescriptor($sDir) Local $aRet = DllCall("Advapi32.dll", "bool", "GetFileSecurityW", _ "wstr", $sDir, _ "dword", BitOR($OWNER_SECURITY_INFORMATION, $GROUP_SECURITY_INFORMATION, $DACL_SECURITY_INFORMATION), _ "ptr", Null, _ "dword", Null, _ "dword*", 0) Local $iBufferSize = $aRet[5] ConsoleWrite("$iNeededSize: " & $iBufferSize & @CRLF) Local $tSecurityDescriptor = DllStructCreate("byte[" & $iBufferSize & "]") $aRet = DllCall("Advapi32.dll", "bool", "GetFileSecurityW", _ "wstr", $sDir, _ "dword", BitOR($OWNER_SECURITY_INFORMATION, $GROUP_SECURITY_INFORMATION, $DACL_SECURITY_INFORMATION), _ "ptr", DllStructGetPtr($tSecurityDescriptor), _ "dword", $iBufferSize, _ "dword*", 0) Return $tSecurityDescriptor EndFunc ;==>_GetSecurityDescriptor Func _MapGenericMask(ByRef $GenericMapping, ByRef $genericAccessRights) Local $aRet = DllCall("Advapi32.dll", "none", "MapGenericMask", "dword*", $genericAccessRights, "ptr", DllStructGetPtr($GenericMapping)) $genericAccessRights = $aRet[1] EndFunc ;==>_MapGenericMask Saludos1 point