Custom Query (3926 matches)
Results (40 - 42 of 3926)
| Ticket | Resolution | Summary | Owner | Reporter |
|---|---|---|---|---|
| #3991 | Completed | _SQLite_ForeignKeys | ||
| Description |
Foreign keys are supported by default by pretty much all important relational database engines and it would be nice to have it by default in SQLite as well or at least a way to enable support when a connection it's made. For this I propose this function _SQLite_ForeignKeys() that enable/disable foreign keys support in SQLite or retrives current foreign_key setting if $bFKEnable is set to Default. ; #FUNCTION# ======================================================================================================================
; Name: _SQLite_ForeignKeys
; Description: Enable or disable foreign key support in SQLite.
; Syntax: _SQLite_ForeignKeys([$hDB = Default[, $bFKEnable = Default]])
; Parameters: $hDB - a database handle (by default it's used the handle of the last opened database).
; $bFKEnable - enable foreign key support if this is set to True or disable foreign key support if this is set to False.
; Return value: Success - Returns current foreign key setting.
; Failure - Returns a value that can be compared against $SQLITE_* constants.
; @error = 1 - Cannot retrieve SQLite library version.
; @error = 2 - Invalid format of SQLite library version.
; @error = 3 - Current SQLite library version does not support foreign keys.
; @error = 4 - Cannot retrieve current foreign keys setting (@extended contains the error code returned by _SQLite_QuerySingleRow).
; @error = 5 - Cannot set foreign keys setting (@extended contains the error code returned by _SQLite_Exec).
; Author: Andreik
; Remarks: This function can be used to retrieve the current foreign key support in SQLite if $bFKEnable is set to Default.
; Link: https://www.autoitscript.com/forum/topic/211365-sqlite-foreign-keys/#comment-1529191
; Example: Yes
; ===============================================================================================================================
Func _SQLite_ForeignKeys($hDB = Default, $bFKEnable = Default)
If $hDB = Default Then $hDB = -1
; Check if SQLite version it's at least 3.6.19 (minimum version that supports foreign key constraints)
Local $sVersion = _SQLite_LibVersion()
If @error Then Return SetError(1, @error, $SQLITE_ERROR)
Local $aMinVersion = StringSplit('3.6.19', '.')
Local $aLibVersion = StringSplit($sVersion, '.')
If $aLibVersion[0] <> 3 Then Return SetError(2, 0, $SQLITE_ERROR)
For $Index = 1 To $aLibVersion[0]
If Int($aLibVersion[$Index]) > Int($aMinVersion[$Index]) Then ExitLoop
If Int($aLibVersion[$Index]) < Int($aMinVersion[$Index]) Then Return SetError(3, 0, $SQLITE_ERROR)
Next
; $bFKEnable = Default - Return current PRAGMA foreign_keys setting
If $bFKEnable = Default Then
Local $aRow
Local $iQueryRet = _SQLite_QuerySingleRow($hDB, 'PRAGMA foreign_keys', $aRow)
If @error Then Return SetError(4, @error, $iQueryRet)
Return SetError(0, 0, $aRow[0] = 1 ? True : False)
EndIf
; $bFKEnable = True - Enable foreign keys
; $bFKEnable = False - Disable foreign keys
Local $iExecRet = _SQLite_Exec($hDB, 'PRAGMA foreign_keys = ' & ($bFKEnable ? 'ON' : 'OFF') & ';')
If $iExecRet = $SQLITE_OK Then
Return SetError(0, 0, $bFKEnable ? True : False)
Else
Return SetError(5, @error, $iExecRet)
EndIf
EndFunc ;==>_SQLite_ForeignKeys
Since this feature must be enable each time at runtime and it's persistent for connection, I propose a new parameter ($bFKEnable) in _SQLite_Open() that can be set to enable foreign keys when a database it's opened. By default this parameter won't modify the actual behavior of _SQLite_Open() unless the $bFKEnable is set to True. So the _SQLite_Open() in this variant should look like this: Func _SQLite_Open($sDatabase_Filename = Default, $iAccessMode = Default, $iEncoding = Default, $bFKEnable = Default) 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 ; Foreign keys support ; ##################################### If $bFKEnable = Default Then $bFKEnable = False If $bFKEnable Then _SQLite_ForeignKeys($avRval[2], $bFKEnable) If @error Then Local $iError = @error _SQLite_Close($avRval[2]) Return SetError(4, $iError, 0) EndIf EndIf ; ##################################### Return SetExtended($avRval[0], $avRval[2]) EndFunc ;==>_SQLite_Open It preserves the code and behavior of the actual function, the only addition it's the last part of the function between # symbols. Here I wrote two examples about how this is suppose to work with this parameter set and unset. https://www.autoitscript.com/forum/topic/211365-sqlite-foreign-keys/#comment-1529191 |
|||
| #1276 | Fixed | _TicksToTime() displayed seconds increment at wrong time | ||
| Description |
In the _TicksToTime function the value for Seconds is derived by this line... $iSecs = Round(Mod($iTicks, 60)) causing the displayed seconds to increment at 500 ms. I believe the code should be... $iSecs = Int(Mod($iTicks, 60)) so seconds only increments at 1000 ms (like a normal clock). |
|||
| #1277 | Fixed | _GDIPlus_ImageGetGraphicsContext needs to be "disposed" in help example | ||
| Description |
The help file gives an example of how to use this function. At the end of the example, the object is NOT DISPOSED. For a novice (like myself) it is not obvious that this object needs to be disposed (otherwise massive memory leak). It seems all the other "create" functions have a matching "dispose" function but not this one. Through trail-and-error I found the required line was... _GDIPlus_GraphicsDispose($hGraphics) |
|||
