Leaderboard
Popular Content
Showing content with the highest reputation on 12/22/2015 in all areas
-
Multi-line items in custom drawn ListView
pixelsearch and one other reacted to LarsJ for a topic
Items in a standard listview in details/report view (this example deals only with listviews in details/report view) can display a single line of text. There seems not to be any options to change this. There is no word wrap option. If you search the forums, it's possible to find examples of listviews with multiple lines of text in each row. The multi-line items are implemented as owner drawn items through LVS_OWNERDRAWFIXED control style and WM_DRAWITEM messages. A problem with the owner drawn technique is that you are forced to draw everything yourself. Besides item texts and the background behind texts (white for non-selected items, dark blue for selected items with focus, button face for selected items without focus) you also have to draw checkboxes, images, icons and the background behind these elements yourself. Another technique is custom drawn listview items. Custom drawn items are implemented through NM_CUSTOMDRAW notifications included in WM_NOTIFY messages. NM_CUSTOMDRAW notifications are generated automatically by the code in ComCtl32.dll when the listview is updated. Implementing custom drawn items is a matter of responding to these messages or not. The great advantage of custom drawn items is that the drawing process is divided into several stages. For a listview up to six different stages. Some of these stages can be used for default drawing without any additional code at all. Other stages can be used for custom drawing with your own code. Multi-line text items fits perfectly with the custom drawn technique. Item texts and the background is drawn by custom code. Checkboxes, images, icons and the background is drawn by default code. Increase height of listview items The usual way to increase the height of listview items is to respond to WM_MEASUREITEM messages. But this method can only be used for owner drawn listviews. In a custom drawn listview the height can be increased by defining a text font with a suitable height: Func _GUICtrlListView_SetItemHeightByFont( $hListView, $iHeight ) ; Get font of ListView control ; Copied from _GUICtrlGetFont example by KaFu ; See https://www.autoitscript.com/forum/index.php?showtopic=124526 Local $hDC = _WinAPI_GetDC( $hListView ), $hFont = _SendMessage( $hListView, $WM_GETFONT ) Local $hObject = _WinAPI_SelectObject( $hDC, $hFont ), $lvLOGFONT = DllStructCreate( $tagLOGFONT ) _WinAPI_GetObject( $hFont, DllStructGetSize( $lvLOGFONT ), DllStructGetPtr( $lvLOGFONT ) ) Local $hLVfont = _WinAPI_CreateFontIndirect( $lvLOGFONT ) ; Original ListView font _WinAPI_SelectObject( $hDC, $hObject ) _WinAPI_ReleaseDC( $hListView, $hDC ) _WinAPI_DeleteObject( $hFont ) ; Set height of ListView items by applying text font with suitable height $hFont = _WinAPI_CreateFont( $iHeight, 0 ) _WinAPI_SetFont( $hListView, $hFont ) _WinAPI_DeleteObject( $hFont ) ; Restore font of Header control Local $hHeader = _GUICtrlListView_GetHeader( $hListView ) If $hHeader Then _WinAPI_SetFont( $hHeader, $hLVfont ) ; Return original ListView font Return $hLVfont EndFunc Large images will also increase the height of listview items. See example E. Height of listview If the height of the listview does not fit an integer number of rows, you can see empty space below last row in the bottom of the listview. This issue is exacerbated by tall items. The following function is used to calculate the height of the listview to match a given number of rows: Func _GUICtrlListView_GetHeightToFitRows( $hListView, $iRows ) ; Get height of Header control Local $tRect = _WinAPI_GetClientRect( $hListView ) Local $hHeader = _GUICtrlListView_GetHeader( $hListView ) Local $tWindowPos = _GUICtrlHeader_Layout( $hHeader, $tRect ) Local $iHdrHeight = DllStructGetData( $tWindowPos , "CY" ) ; Get height of ListView item 0 (item 0 must exist) Local $aItemRect = _GUICtrlListView_GetItemRect( $hListView, 0, 0 ) ; Return height of ListView to fit $iRows items ; Including Header height and 8 pixels of additional room Return ( $aItemRect[3] - $aItemRect[1] ) * $iRows + $iHdrHeight + 8 EndFunc The calculation includes the height of the header. This means that the function works for a multi-line header with tall items (example A and B). Reference example WM_NOTIFY messages and NM_CUSTOMDRAW notifications are send to the parent of the listview control. The parent is the AutoIt GUI and messages can be handled by a function registered with GUIRegisterMsg. Example 1 is a reference example which shows the different stages of the custom drawing process. None of the stages contains any code except for ConsoleWrite statements. This is code for the reference example: #include <GUIConstants.au3> #include <GuiListView.au3> #include "GuiListViewEx.au3" Opt( "MustDeclareVars", 1 ) Global $hGui, $idListView, $hListView, $fListViewHasFocus = 0, $iItems = 3, $bAutoItMsgLoop = False Example() Func Example() ; Create GUI $hGui = GUICreate( "Custom draw stages", 420, 200 ) ; Create ListView $idListView = GUICtrlCreateListView( "", 10, 10, 400, 180, $GUI_SS_DEFAULT_LISTVIEW-$LVS_SINGLESEL, $WS_EX_CLIENTEDGE+$LVS_EX_FULLROWSELECT+$LVS_EX_GRIDLINES ) $hListView = GUICtrlGetHandle( $idListView ) ; Add columns to ListView _GUICtrlListView_AddColumn( $hListView, "Column 1", 94 ) _GUICtrlListView_AddColumn( $hListView, "Column 2", 94 ) _GUICtrlListView_AddColumn( $hListView, "Column 3", 94 ) _GUICtrlListView_AddColumn( $hListView, "Column 4", 94 ) ; Fill ListView For $i = 0 To $iItems - 1 GUICtrlCreateListViewItem( $i & "/Column 1|" & $i & "/Column 2|" & $i & "/Column 3|" & $i & "/Column 4", $idListView ) Next ; Adjust height of GUI and ListView to fit ten rows Local $iLvHeight = _GUICtrlListView_GetHeightToFitRows( $hListView, 10 ) WinMove( $hGui, "", Default, Default, Default, WinGetPos( $hGui )[3] - WinGetClientSize( $hGui )[1] + $iLvHeight + 20 ) WinMove( $hListView, "", Default, Default, Default, $iLvHeight ) ; Register WM_NOTIFY message handler ; To handle NM_CUSTOMDRAW notifications ; And to check when ListView receives/loses focus GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) ; Register WM_ACTIVATE message handler ; If GUI loses focus selected listview items are drawn with a button face background color. ; To check when GUI receives/loses focus ; When GUI receives focus selected items are redrawn with the dark blue background color. GUIRegisterMsg( $WM_ACTIVATE, "WM_ACTIVATE" ) ; Detection of received focus is faster through the WM_ACTIVATE message than directly ; through the listview. This provides a faster and smoother redraw of selected items. ; Show GUI GUISetState( @SW_SHOW ) ; Message loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch If Not $bAutoItMsgLoop Then _ ; We want to see only one message at a time $bAutoItMsgLoop = ( ConsoleWrite( "AutoIt message loop <<<<<<<<<<<<<<<<<<<<<" & @CRLF ) > 0 ) WEnd ; Cleanup GUIDelete() EndFunc ; WM_NOTIFY message handler Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) Local $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) Local $iCode = DllStructGetData( $tNMHDR, "Code" ) Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW $bAutoItMsgLoop = False Local $tNMLVCustomDraw = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMLVCustomDraw, "dwDrawStage" ) Switch $dwDrawStage ; Specifies the drawing stage ; Stage 1 Case $CDDS_PREPAINT ; Before the paint cycle begins ConsoleWrite( "Stage 1: CDDS_PREPAINT" & @CRLF ) Return $CDRF_NOTIFYITEMDRAW + _ ; Stage 2 will be carried out $CDRF_NOTIFYPOSTPAINT ; Stage 6 will be carried out Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window before an item is painted Return $CDRF_NOTIFYPOSTPAINT ; Notify the parent window after the paint cycle is complete ; Stage 2 Case $CDDS_ITEMPREPAINT ; Before an item is painted ConsoleWrite( "Stage 2: CDDS_ITEMPREPAINT" & @CRLF ) Return $CDRF_NOTIFYSUBITEMDRAW + _ ; Stage 3 will be carried out $CDRF_NOTIFYPOSTPAINT ; Stage 5 will be carried out Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window before a subitem is painted Return $CDRF_NOTIFYPOSTPAINT ; Notify the parent window after an item is painted ; Stage 3 Case BitOR( $CDDS_ITEMPREPAINT, _ $CDDS_SUBITEM ) ; Before a subitem is painted ConsoleWrite( "Stage 3: CDDS_ITEMPREPAINT, CDDS_SUBITEM" & @CRLF ) Return $CDRF_NOTIFYPOSTPAINT ; Stage 4 will be carried out Return $CDRF_NOTIFYPOSTPAINT ; Notify the parent window after a subitem is painted ; Stage 4 Case BitOR( $CDDS_ITEMPOSTPAINT, _ $CDDS_SUBITEM ) ; After a subitem has been painted ConsoleWrite( "Stage 4: CDDS_ITEMPOSTPAINT, CDDS_SUBITEM" & @CRLF ) ; Stage 5 Case $CDDS_ITEMPOSTPAINT ; After an item has been painted ConsoleWrite( "Stage 5: CDDS_ITEMPOSTPAINT" & @CRLF ) ; Stage 6 Case $CDDS_POSTPAINT ; After the paint cycle is complete ConsoleWrite( "Stage 6: CDDS_POSTPAINT" & @CRLF ) EndSwitch Case $NM_KILLFOCUS If $fListViewHasFocus Then GUICtrlSendMsg( $idListView, $LVM_REDRAWITEMS, 0, $iItems - 1 ) $fListViewHasFocus = 0 EndIf Case $NM_SETFOCUS If Not $fListViewHasFocus Then _ GUICtrlSendMsg( $idListView, $LVM_REDRAWITEMS, 0, $iItems - 1 ) $fListViewHasFocus = 2 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ; WM_ACTIVATE message handler Func WM_ACTIVATE( $hWnd, $iMsg, $wParam, $lParam ) #forceref $iMsg, $lParam If $hWnd = $hGui Then _ $fListViewHasFocus = BitAND( $wParam, 0xFFFF ) ? 1 : 0 Return $GUI_RUNDEFMSG EndFunc Code is added to check when GUI and listview receives and loses focus. This is important in the other examples. Output in SciTE console immediately after example is opened: Stage 1: CDDS_PREPAINT Stage 2: CDDS_ITEMPREPAINT Stage 3: CDDS_ITEMPREPAINT, CDDS_SUBITEM Stage 4: CDDS_ITEMPOSTPAINT, CDDS_SUBITEM Stage 3: CDDS_ITEMPREPAINT, CDDS_SUBITEM Stage 4: CDDS_ITEMPOSTPAINT, CDDS_SUBITEM Stage 3: CDDS_ITEMPREPAINT, CDDS_SUBITEM Stage 4: CDDS_ITEMPOSTPAINT, CDDS_SUBITEM Stage 3: CDDS_ITEMPREPAINT, CDDS_SUBITEM Stage 4: CDDS_ITEMPOSTPAINT, CDDS_SUBITEM Stage 5: CDDS_ITEMPOSTPAINT Stage 2: CDDS_ITEMPREPAINT Stage 3: CDDS_ITEMPREPAINT, CDDS_SUBITEM Stage 4: CDDS_ITEMPOSTPAINT, CDDS_SUBITEM Stage 3: CDDS_ITEMPREPAINT, CDDS_SUBITEM Stage 4: CDDS_ITEMPOSTPAINT, CDDS_SUBITEM Stage 3: CDDS_ITEMPREPAINT, CDDS_SUBITEM Stage 4: CDDS_ITEMPOSTPAINT, CDDS_SUBITEM Stage 3: CDDS_ITEMPREPAINT, CDDS_SUBITEM Stage 4: CDDS_ITEMPOSTPAINT, CDDS_SUBITEM Stage 5: CDDS_ITEMPOSTPAINT Stage 2: CDDS_ITEMPREPAINT Stage 3: CDDS_ITEMPREPAINT, CDDS_SUBITEM Stage 4: CDDS_ITEMPOSTPAINT, CDDS_SUBITEM Stage 3: CDDS_ITEMPREPAINT, CDDS_SUBITEM Stage 4: CDDS_ITEMPOSTPAINT, CDDS_SUBITEM Stage 3: CDDS_ITEMPREPAINT, CDDS_SUBITEM Stage 4: CDDS_ITEMPOSTPAINT, CDDS_SUBITEM Stage 3: CDDS_ITEMPREPAINT, CDDS_SUBITEM Stage 4: CDDS_ITEMPOSTPAINT, CDDS_SUBITEM Stage 5: CDDS_ITEMPOSTPAINT Stage 6: CDDS_POSTPAINT AutoIt message loop <<<<<<<<<<<<<<<<<<<<< Note that the entire custom draw process from stage 1 to 6 is not interrupted by the AutoIt message loop. The other examples are all based on the reference example. Examples This is common to all examples. First line in item texts is stored directly in the listview. Additional lines are stored in a global array named $aLines. Index in the array is item ID as returned by GUICtrlCreateListViewItem and stored in ItemParam internally in listview memory. Item texts and background is drawn with custom code. Other item elements and background is drawn with default code. In all examples LVS_SINGLESEL style is removed to be able to select multiple items. This is a picture of example E: Example 2, 3 and 4 are simple examples. Example 5 and 6 deals with subitem icons and colors. Example 7 about listview notifications shows a way to catch double click and Enter key. A dummy control is used to forward the double click event to AutoIt main message loop to avoid lengthy or blocking code in WM_NOTIFY function. Example 8 and 9 shows how to respond to header notifications and how to rearrange columns by dragging header items with the mouse. In both examples LVS_EX_HEADERDRAGDROP extended style is added to the listview. When columns are rearranged, header item index and listview subitem index is always the same independent of column position, while header item order changes depending on column position. Because the header is a child control of the listview, the listview must be subclassed to catch header notifications. Subclassing is implemented with the four functions SetWindowSubclass, GetWindowSubclass, RemoveWindowSubclass and DefSubclassProc (all implemented in WinAPIShellEx.au3). Since we are subclassing a header control contained in a listview this issue must be taking into account. Note that the subclass callback function is only running while the primary mouse button is pressed on the header. This means no performance impact on the listview eg. when you are dragging the scroll bar. This is important for a custom drawn listview. Quite a lot of extra code is added (most easily seen in example 9) to fix an issue due to column 0 and other columns have different left margins. When first column is moved to another position there is a white gap between columns for selected rows (Windows XP), or the text is painted too close to the left edge of the item (Windows 7). The problem is seen in the picture to the right where the two first columns are swapped: LVS_EX_HEADERDRAGDROP style is only used in example 8 and 9. Usage of a multi-line header is demonstrated in example A and B. See Custom/owner drawn multi-line header in ListView for more information. Example C shows a method to deal with focus issues when more controls (here just a single button) are added to the GUI. When the listview has focus selected items are drawn with the dark blue background color. The problem arises if the listview and GUI loses focus eg. to Calculator. When focus is lost selected items are drawn with the button face background color. If GUI receives focus again by clicking the button (and not the listview), selected items are first very briefly redrawn with the dark blue background color (it seems like a blink) and then with the correct button face background color. To avoid this issue a hidden label control is added to the GUI. Immediately before the GUI loses focus, focus is moved from the listview to the label. In example D items are added with the commands _GUICtrlListView_AddItem and _GUICtrlListView_AddSubItem. In all examples an array is used to store the multi-line item texts. The array contains all lines except the first line which is stored directly in the listview. This example shows how to manually store array row index in ItemParam when items are added with _GUICtrlListView_AddItem and _GUICtrlListView_AddSubItem. Inspiration for example E about large images in first column (see picture above) comes from this thread. In example E the images are used to increase the height of the listview items instead of a text font. Because it's large 128x128 pixel images there is plenty of room in subitems in second and third column. In all examples 15 lines of code is used to repaint the first line item text. The text that was painted by default code in middle of the item is first deleted by filling the item with the background color. Then the text is extracted from the listview and repainted in top of item. This code can be avoided by storing all text lines in the array. This is demonstrated in example F. This makes the custom draw code faster. Performance considerations In a custom drawn (or owner drawn or virtual) listview performance considerations are important because the custom drawing (or owner drawing or data display) is performed by AutoIt code. In a normal listview drawing and data display is performed by compiled C++ code in ComCtl32.dll. Lengthy and slow code in NM_CUSTOMDRAW Case statements (or WM_DRAWITEM functions or LVN_GETDISPINFO Case statements) should be avoided. Perform as many calculations as possible before the repetitive and fast executions of these code blocks. Use static variables to avoid repeating the same calculation again and again. Executing a function directly with DllCall or GUICtrlSendMsg is faster than executing the same function through an implementation in an UDF. Simple GDI functions are faster than more advanced GDI+ functions. Use different drawing stages to optimize custom drawing. The CDDS_PREPAINT stage is only performed once for the entire drawing process. The CDDS_ITEMPREPAINT stage is performed once per item. The stage given by BitOR( CDDS_ITEMPREPAINT, CDDS_SUBITEM ) is performed once per subitem including subitem 0. Default drawing should be used as much as possible, because the code is running in ComCtl32.dll. In a listview the time it takes to update all visible rows is proportional to the number of visible rows. Reducing the height of the list view and thus the number of visible rows improves performance. Especially in a custom drawn (or owner drawn or virtual) listview. ListviewMultilineItems.7z 1) Custom draw stages.au3 2) Two-line listview items.au3 3) Three-line listview items.au3 4) First column checkbox and icon.au3 5) Check boxes and icons.au3 6) Background and text colors.au3 7) ListView notifications.au3 8) Header notifications.au3 9) Rearrange columns.au3 A) Multi-line header 1.au3 A) Multi-line header 2.au3 C) Button control.au3 D) _GUICtrlListView_AddItem.au3 E) Large images in first column.au3 F) Storing all lines in array.au3 GuiHeaderEx.au3 GuiListViewEx.au3 ListViewCustomDraw.au3 Images\ 8 images for example E You need AutoIt 3.3.10 or later. Tested on Windows 7 32/64 bit and Windows XP 32 bit. Comments are welcome. Let me know if there are any issues. (Set tab width = 2 in SciTE to line up comments by column.) ListviewMultilineItems.7z2 points -
I very long time was using In the end, I found that at present my needs I need to modify it. And here it is: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;~ #AutoIt3Wrapper_Run_Debug_Mode=Y ;(Y/N) Run Script with console debugging. Default=N #Region INCLUDE ;################################## ; Include ;################################## #include <file.au3> #EndRegion INCLUDE #Region Variables ;################################## ; Variables ;################################## Global Enum _ $g__INetSmtpMailCom_ERROR_FileNotFound = 1, _ $g__INetSmtpMailCom_ERROR_Send, _ $g__INetSmtpMailCom_ERROR_ObjectCreation, _ $g__INetSmtpMailCom_ERROR_COUNTER Global Const $g__cdoSendUsingPickup = 1 ; Send message using the local SMTP service pickup directory. Global Const $g__cdoSendUsingPort = 2 ; Send the message using the network (SMTP over the network). Must use this to use Delivery Notification Global Const $g__cdoAnonymous = 0 ; Do not authenticate Global Const $g__cdoBasic = 1 ; basic (clear-text) authentication Global Const $g__cdoNTLM = 2 ; NTLM ; Delivery Status Notifications Global Const $g__cdoDSNDefault = 0 ; None Global Const $g__cdoDSNNever = 1 ; None Global Const $g__cdoDSNFailure = 2 ; Failure Global Const $g__cdoDSNSuccess = 4 ; Success Global Const $g__cdoDSNDelay = 8 ; Delay Global Const $g__cdoDSNSuccessFailOrDelay = 14 ; Success, failure or delay #EndRegion Variables #Region Example Script ;################################## ; Example Script ;################################## ;~ _Example() Func _Example() Local $sSmtpServer = "MailServer" ; address for the smtp-server to use - REQUIRED Local $sFromName = "Name" ; name from who the email was sent Local $sFromAddress = "your@Email.Address.com" ; address from where the mail should come Local $sToAddress = "your@Email.Address.com" ; destination address of the email - REQUIRED Local $sSubject = "Userinfo" ; subject from the email - can be anything you want it to be Local $sBody = "" ; the messagebody from the mail - can be left blank but then you get a blank mail Local $sAttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed Local $sCcAddress = "CCadress1@test.com" ; address for cc - leave blank if not needed Local $sBccAddress = "BCCadress1@test.com" ; address for bcc - leave blank if not needed Local $sImportance = "Normal" ; Send message priority: "High", "Normal", "Low" Local $sUsername = "******" ; username for the account used from where the mail gets sent - REQUIRED Local $sPassword = "********" ; password for the account used from where the mail gets sent - REQUIRED Local $iIPPort = 25 ; port used for sending the mail Local $bSSL = False ; enables/disables secure socket layer sending - set to True if using httpS ; Local $iIPPort = 465 ; GMAIL port used for sending the mail ; Local $bSSL = True ; GMAIL enables/disables secure socket layer sending - set to True if using httpS Local $bIsHTMLBody = False Local $iDSNOptions = $g__cdoDSNDefault Local $rc = _INetSmtpMailCom($sSmtpServer, $sFromName, $sFromAddress, $sToAddress, $sSubject, $sBody, $sAttachFiles, $sCcAddress, $sBccAddress, $sImportance, $sUsername, $sPassword, $iIPPort, $bSSL, $bIsHTMLBody, $iDSNOptions) If @error Then MsgBox(0, "_INetSmtpMailCom(): Error sending message", _ "Error code: " & @error & @CRLF & @CRLF & _ "Error Hex Number: " & _INetSmtpMailCom_ErrHexNumber() & @CRLF & @CRLF & _ "Description: " & _INetSmtpMailCom_ErrDescription() & @CRLF & @CRLF & _ "Description (rc): " & $rc & @CRLF & @CRLF & _ "ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() _ ) ConsoleWrite("### COM Error ! Number: " & _INetSmtpMailCom_ErrHexNumber() & " ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() & " Description:" & _INetSmtpMailCom_ErrDescription() & @LF) EndIf EndFunc ;==>_Example #EndRegion Example Script #Region UDF Functions ; The UDF ; #FUNCTION# ==================================================================================================================== ; Name ..........: _INetSmtpMailCom ; Description ...: ; Syntax ........: _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress[, $s_Subject = ""[, $as_Body = ""[, ; $s_AttachFiles = ""[, $s_CcAddress = ""[, $s_BccAddress = ""[, $s_Importance = "Normal"[, $s_Username = ""[, ; $s_Password = ""[, $IPPort = 25[, $bSSL = False[, $bIsHTMLBody = False[, $iDSNOptions = $g__cdoDSNDefault]]]]]]]]]]]]) ; Parameters ....: $s_SmtpServer - A string value. ; $s_FromName - A string value. ; $s_FromAddress - A string value. ; $s_ToAddress - A string value. ; $s_Subject - [optional] A string value. Default is "". ; $s_Body - [optional] A string value. Default is "". ; $s_AttachFiles - [optional] A string value. Default is "". ; $s_CcAddress - [optional] A string value. Default is "". ; $s_BccAddress - [optional] A string value. Default is "". ; $s_Importance - [optional] A string value. Default is "Normal". ; $s_Username - [optional] A string value. Default is "". ; $s_Password - [optional] A string value. Default is "". ; $IPPort - [optional] An integer value. Default is 25. ; $bSSL - [optional] A binary value. Default is False. ; $bIsHTMLBody - [optional] A binary value. Default is False. ; $iDSNOptions - [optional] An integer value. Default is $g__cdoDSNDefault. ; Return values .: None ; Author ........: Jos ; Modified ......: mLipok ; Remarks .......: ; Related .......: http://www.autoitscript.com/forum/topic/23860-smtp-mailer-that-supports-html-and-attachments/ ; Link ..........: http://www.autoitscript.com/forum/topic/167292-smtp-mailer-udf/ ; Example .......: Yes ; =============================================================================================================================== Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $s_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance = "Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $bSSL = False, $bIsHTMLBody = False, $iDSNOptions = $g__cdoDSNDefault) ; init Error Handler _INetSmtpMailCom_ErrObjInit() Local $objEmail = ObjCreate("CDO.Message") If Not IsObj($objEmail) Then Return SetError($g__INetSmtpMailCom_ERROR_ObjectCreation, Dec(_INetSmtpMailCom_ErrHexNumber()), _INetSmtpMailCom_ErrDescription()) ; Clear previous Err information _INetSmtpMailCom_ErrHexNumber(0) _INetSmtpMailCom_ErrDescription('') _INetSmtpMailCom_ErrScriptLine('') $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject ; Select whether or not the content is sent as plain text or HTM If $bIsHTMLBody Then $objEmail.Textbody = $s_Body & @CRLF Else $objEmail.HTMLBody = $s_Body EndIf ; Add Attachments If $s_AttachFiles <> "" Then Local $S_Files2Attach = StringSplit($s_AttachFiles, ";") For $x = 1 To $S_Files2Attach[0] $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x]) If FileExists($S_Files2Attach[$x]) Then ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF) $objEmail.AddAttachment($S_Files2Attach[$x]) Else ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF) Return SetError($g__INetSmtpMailCom_ERROR_FileNotFound, 0, 0) EndIf Next EndIf ; Set Email Configuration $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = $g__cdoSendUsingPort $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 Then $IPPort = 25 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = $g__cdoBasic $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = $bSSL ;Update Configuration Settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Low" EndSwitch ; Set DSN options If $iDSNOptions <> $g__cdoDSNDefault And $iDSNOptions <> $g__cdoDSNNever Then $objEmail.DSNOptions = $iDSNOptions $objEmail.Fields.Item("urn:schemas:mailheader:disposition-notification-to") = $s_FromAddress ;~ $objEmail.Fields.Item("urn:schemas:mailheader:return-receipt-to") = $s_FromAddress EndIf ; Update Importance and Options fields $objEmail.Fields.Update ; Sent the Message $objEmail.Send If @error Then _INetSmtpMailCom_ErrObjCleanUp() Return SetError($g__INetSmtpMailCom_ERROR_Send, Dec(_INetSmtpMailCom_ErrHexNumber()), _INetSmtpMailCom_ErrDescription()) EndIf ; CleanUp $objEmail = "" _INetSmtpMailCom_ErrObjCleanUp() EndFunc ;==>_INetSmtpMailCom ; ; Com Error Handler Func _INetSmtpMailCom_ErrObjInit($bParam = Default) Local Static $oINetSmtpMailCom_Error = Default If $bParam == 'CleanUp' And $oINetSmtpMailCom_Error <> Default Then $oINetSmtpMailCom_Error = '' Return $oINetSmtpMailCom_Error EndIf If $oINetSmtpMailCom_Error = Default Then $oINetSmtpMailCom_Error = ObjEvent("AutoIt.Error", "_INetSmtpMailCom_ErrFunc") EndIf Return $oINetSmtpMailCom_Error EndFunc ;==>_INetSmtpMailCom_ErrObjInit Func _INetSmtpMailCom_ErrObjCleanUp() _INetSmtpMailCom_ErrObjInit('CleanUp') EndFunc ;==>_INetSmtpMailCom_ErrObjCleanUp Func _INetSmtpMailCom_ErrHexNumber($vData = Default) Local Static $vReturn = 0 If $vData <> Default Then $vReturn = $vData Return $vReturn EndFunc ;==>_INetSmtpMailCom_ErrHexNumber Func _INetSmtpMailCom_ErrDescription($sData = Default) Local Static $sReturn = '' If $sData <> Default Then $sReturn = $sData Return $sReturn EndFunc ;==>_INetSmtpMailCom_ErrDescription Func _INetSmtpMailCom_ErrScriptLine($iData = Default) Local Static $iReturn = '' If $iData <> Default Then $iReturn = $iData Return $iReturn EndFunc ;==>_INetSmtpMailCom_ErrScriptLine Func _INetSmtpMailCom_ErrFunc() _INetSmtpMailCom_ErrObjInit() _INetSmtpMailCom_ErrHexNumber(Hex(_INetSmtpMailCom_ErrObjInit().number, 8)) _INetSmtpMailCom_ErrDescription(StringStripWS(_INetSmtpMailCom_ErrObjInit().description, 3)) _INetSmtpMailCom_ErrScriptLine(_INetSmtpMailCom_ErrObjInit().ScriptLine) SetError(1); something to check for when this function returns Return EndFunc ;==>_INetSmtpMailCom_ErrFunc #EndRegion UDF Functions Creating this modification, I had to: 1. Object Error Handler used only for the duration of the function of Use, 2. Automatic ErrorHandler CleanUp so that previous ErrorHandler took the job. 3. Ability to get ErrorNumber and ErrorDescription ErrorScriptLine information even after the end of the function 4. Elimination of most global variables mLipok EDIT: attached SmtpMailer_UDF.au3 file EDIT 2: Any comments are welcome. EDIT 3: Script CleanUp EDIT 4: Download moved to "Download Section" (previously downloaded 379 times) EDIT 5: at 2016/01/31 there was many script breaking changes1 point
-
Checkboxes If LVS_EX_CHECKBOXES extended style is applied to a listview, two images are automatically added to the state image list: An unchecked checkbox (index 0) and a checked checkbox (index 1). You can get a handle for the state image list with $hStateImageList = _GUICtrlListView_GetImageList( $hListView, 2 ) ; 2 = Image list with state images Then you can set the state image list as a normal small icon image list: _GUICtrlListView_SetImageList( $hListView, $hStateImageList, 1 ) ; 1 = Image list with small icons If you apply this code line to all listview items the result is two checkboxes in first column: _GUICtrlListView_SetItemImage( $hListView, $iItem, 0 ) ; Unchecked checkbox (index 0) for $iItem Use this code line to add subitem checkboxes (requires LVS_EX_SUBITEMIMAGES extended style) to fourth column: _GUICtrlListView_SetItemImage( $hListView, $iItem, 0, 3 ) ; 3 is the zero based index of fourth column Another consequence of LVS_EX_CHECKBOXES extended style is that the image is automatically switched between the unchecked and checked ckeckbox when you click the icon. You have to implement this functionality yourself for the checkboxes added through the normal image list. This is easily done by responding to NM_CLICK events in a WM_NOTIFY message handler: Case $NM_CLICK Local $aHit = _GUICtrlListView_SubItemHitTest( $hListView ) If $aHit[6] Then ; On item? If $aHit[3] Then ; On icon? If $aHit[1] = 0 Or $aHit[1] = 3 Then ; On subitem 0 or 3? Local $iImage = _GUICtrlListView_GetItemImage( $hListView, $aHit[0], $aHit[1] ) ; Image index 0 or 1 _GUICtrlListView_SetItemImage( $hListView, $aHit[0], $iImage ? 0 : 1, $aHit[1] ) ; Switch index value EndIf ; $iItem $iImage $iSubItem EndIf EndIf The above is demonstrated in example 1) Subitem checkboxes.au3. If you don't want checkboxes for all of the listview items example 2) Remove some checkboxes.au3 shows how to remove some of the checkboxes. This is a picture of example 2: In example 1 and 2 the selected and focused states are removed from the listview items. Overlay icons In this picture of example 3) Overlay icons.au3 you can see cyan, green and yellow overlay icons on top of the original item icons: Overlay icons are stored in the small and large image lists. The function ImageList_SetOverlayImage implemented in GuiImageListEx.au3 tells the image list that this is a special image that is used as an overlay icon. Overlay icons must be stored among the first 15 images in the image list. To apply an overlay icon to a listview item the one based image index of the overlay icon must be stored in bits 8 - 11 in the state member of the LVITEM structure. Because 4 bits are used to store the image index you can only use 15 overlay icons. If all 4 bits are zero, it means that there is no overlay icon. Use these commands to add cyan, green and yellow overlay icons as the first three images in the image list: _GUIImageList_AddIcon( $hImageList, "icons\Cyan.ico" ) ; Index 0 _GUIImageList_AddIcon( $hImageList, "icons\Green.ico" ) ; Index 1 _GUIImageList_AddIcon( $hImageList, "icons\Yellow.ico" ) ; Index 2 Tell the imagelist that this is overlay icons: ImageList_SetOverlayImage( $hImageList, 0, 1 ) ; First overlay icon ImageList_SetOverlayImage( $hImageList, 1, 2 ) ; Second overlay icon ImageList_SetOverlayImage( $hImageList, 2, 3 ) ; Third overlay icon Add overlay icons to listview items A, B, C (256 = 2^8 is the value of bit 8): _GUICtrlListView_SetItemState( $hListView, $iItemA, 1 * 256 , $LVIS_OVERLAYMASK ) ; First overlay icon, cyan _GUICtrlListView_SetItemState( $hListView, $iItemB, 2 * 256 , $LVIS_OVERLAYMASK ) ; Second overlay icon, green _GUICtrlListView_SetItemState( $hListView, $iItemC, 3 * 256 , $LVIS_OVERLAYMASK ) ; Third overlay icon, yellow _GUICtrlListView_SetItemState( $hListView, $iItemD, 0 * 256 , $LVIS_OVERLAYMASK ) ; Remove an overlay icon State images If you want to use your own custom state images eg. green, yellow and red images (to signal ok, warning and error) instead of checkboxes, apply the LVS_EX_CHECKBOXES extended style to the listview, get a handle to the state image list, delete the images of the unchecked (index 0) and checked (index 1) checkboxes and add the green, yellow and red images to the state image list. Add custom state images to listview items A, B, C: _GUICtrlListView_SetItemStateImage( $hListView, $iItemA, 1 ) ; First state image, green _GUICtrlListView_SetItemStateImage( $hListView, $iItemB, 2 ) ; Second state image, yellow _GUICtrlListView_SetItemStateImage( $hListView, $iItemC, 3 ) ; Third state image, red _GUICtrlListView_SetItemStateImage( $hListView, $iItemD, 0 ) ; Remove a state image If you click a green state image, the image switches to yellow. If you click a yellow state image, it switches to red. If you click a red state image, it switches to green again. No code is needed for the image switching. It's a consequence of the LVS_EX_CHECKBOXES extended style. This is demonstrated in example 4) State images.au3. CheckboxesAndIcons.7z icons\ - Overlay icons 1) Subitem checkboxes.au3 2) Remove some checkboxes.au3 3) Overlay icons.au3 4) State images.au3 GuiImageListEx.au3 GuiListViewEx.au3 You need AutoIt 3.3.10 or later. Tested on Windows 7 32/64 bit and Windows XP 32 bit. Comments are welcome. Let me know if there are any issues. (Set tab width = 2 in SciTE to line up comments by column.) CheckboxesAndIcons.7z1 point
-
? #include <ie.au3> Local $sNewContent = ClipGet(), $sLastContent = $sNewContent, $oForm Local $oIe = _IECreate("https://www.google.com") Local $hIe = _IEPropertyGet($oIe, "hwnd") While WinExists($hIe) Sleep(500) $sNewContent = ClipGet() If Not @error Then ; some text was in the ClipBoard If $sNewContent <> $sLastContent Then ; the clipboard content has changed $sLastContent = $sNewContent _IENavigate($oIe, "https://www.google.com/?q=" & ClipGet()) $oForm = _IEFormGetCollection($oIe, 0) _IEFormSubmit($oForm) EndIf EndIf WEnd1 point
-
Microsoft Access database Second version
123disconnect reacted to wolf9228 for a topic
Microsoft Access database Second version MS_AccessDB.zip New in this version - ODBC UNICODE Functions - Improvements to the SetBinary function - General improvements to the project functions ODBC is an API that uses Structured Query Language (SQL) as the database access language. You can access a wide variety of database management systems (DBMSs) with the same ODBC source code that is directly incorporated into an application's source code. With the Microsoft ODBC Desktop Database Drivers, a user of an ODBC-enabled application can open, query, and update a desktop database through the ODBC interface. The Microsoft ODBC Desktop Database Drivers are a Microsoft Jet-based set of ODBC drivers. Whereas Microsoft ODBC Desktop Database Drivers 2.0 include both 16-bit and 32-bit drivers, versions 3.0 and later include only 32-bit drivers that work on Windows 95 or later, Windows NT Workstation or Server version 4.0, Windows 2000 Professional, or Windows 2000 Server. These drivers provide access to the following types of data sources: Microsoft Access Microsoft Excel Paradox dBASE Text Microsoft Access Driver Programming Consideration http://msdn.microsoft.com/en-us/library/windows/desktop/ms710302%28v=vs.85%29.aspx Microsoft Access Data Types http://msdn.microsoft.com/en-us/library/windows/desktop/ms714540%28v=vs.85%29.aspx Microsoft Access Data Types http://www.w3schools.com/sql/sql_datatypes.asp MS_AccessDB.au3 #Include <WinAPI.au3> #include <Math.au3> Global $odbc32 = DllOpen("odbc32.dll") , $StructToString = False , $AUTOCOMMIT = True Func MS_AccessDatabaseCreate($DbFileName = "MSDataBase.mdb",$DshWnd = 0,$OverExFile = False) ; $OverExFile ==> overwrite existing file Local $ODBC_ADD_SYS_DSN = 4 Local $lpszDriver = "Microsoft Access Driver (*.MDB)" & Chr(0) Local $lpszAttributes = "CREATE_DB=" & $DbFileName & " General" & Chr(0) if Not($DshWnd) Then $DshWnd = _WinAPI_GetDesktopWindow() if ($OverExFile) And (FileExists($DbFileName)) Then if Not(FileDelete($DbFileName)) Then Return SetError(1,0,False) EndIf Local $Return = DllCall("odbccp32.dll","BOOL","SQLConfigDataSourceW","HWND",$DshWnd , _ "WORD",$ODBC_ADD_SYS_DSN,"wstr",$lpszDriver,"wstr",$lpszAttributes) if @error Or Not($Return[0]) Then Return SetError(2,0,False) Return SetError(0,0,True) EndFunc Func MS_AccessDatabaseConnect($DbFileName = "MSDataBase.mdb",$DshWnd = 0) Local $SQL_HANDLE_ENV = 1 , $SQL_NULL_HANDLE = 0 , $SQL_ATTR_ODBC_VERSION = 200 Local $SQL_OV_ODBC3 = 3,$Return = 0,$SQL_HANDLE_DBC = 2,$SQL_LOGIN_TIMEOUT = 103 Local $SQL_SUCCESS = 0 , $SQL_SUCCESS_WITH_INFO = 1 , $SQL_DRIVER_NOPROMPT = 0 Local $TIMEOUT = 5 , $hDatabase[2], $SQL_AUTOCOMMIT = 102,$SQL_AUTOCOMMIT_ON = 1 Local $SQL_IS_INTEGER = -6 Local $InConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & $DbFileName if Not($DshWnd) Then $DshWnd = _WinAPI_GetDesktopWindow() Local $Return = DllCall($odbc32,"short","SQLAllocHandle", _ "short",$SQL_HANDLE_ENV,"ptr",$SQL_NULL_HANDLE,"ptr*",0) if @error Or ($Return[0] <> $SQL_SUCCESS And $Return[0] <> $SQL_SUCCESS_WITH_INFO) Then Return SetError(1,0,0) EndIf Local $henv = $Return[3] $Return = DllCall("odbc32.dll","short","SQLSetEnvAttr","ptr",$henv, _ "long",$SQL_ATTR_ODBC_VERSION,"long",$SQL_OV_ODBC3,"long",0) if @error Or ($Return[0] <> $SQL_SUCCESS And $Return[0] <> $SQL_SUCCESS_WITH_INFO) Then DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_ENV,"ptr",$henv) Return SetError(2,0,0) EndIf $Return = DllCall($odbc32,"short","SQLAllocHandle","short",$SQL_HANDLE_DBC,"ptr",$henv,"ptr*",0) if @error Or ($Return[0] <> $SQL_SUCCESS And $Return[0] <> $SQL_SUCCESS_WITH_INFO) Then DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_ENV,"ptr",$henv) Return SetError(3,0,0) EndIf Local $hdbc = $Return[3] $Return = DllCall($odbc32,"short","SQLSetConnectAttr","ptr", _ $hdbc,"long",$SQL_LOGIN_TIMEOUT,"long",$TIMEOUT,"long",$SQL_IS_INTEGER) if @error Or ($Return[0] <> $SQL_SUCCESS And $Return[0] <> $SQL_SUCCESS_WITH_INFO) Then DllCall($odbc32,"short","SQLDisconnect","ptr",$hdbc) DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_DBC,"ptr",$hdbc) DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_ENV,"ptr",$henv) Return SetError(4,0,0) EndIf if ($AUTOCOMMIT) Then $Return = DllCall($odbc32,"short","SQLSetConnectAttr","ptr", _ $hdbc,"long",$SQL_AUTOCOMMIT,"long",$SQL_AUTOCOMMIT_ON,"long",$SQL_IS_INTEGER) if @error Or ($Return[0] <> $SQL_SUCCESS And $Return[0] <> $SQL_SUCCESS_WITH_INFO) Then DllCall($odbc32,"short","SQLDisconnect","ptr",$hdbc) DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_DBC,"ptr",$hdbc) DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_ENV,"ptr",$henv) Return SetError(5,0,0) EndIf EndIf $Return = DllCall($odbc32,"short","SQLDriverConnectW", _ "ptr",$hdbc ,"HWND",$DshWnd,"wstr",$InConnectionString, _ "short",-3,"ptr",0,"short",0,"short*",0,"short",$SQL_DRIVER_NOPROMPT) if @error Or ($Return[0] <> $SQL_SUCCESS And $Return[0] <> $SQL_SUCCESS_WITH_INFO) Then DllCall($odbc32,"short","SQLDisconnect","ptr",$hdbc) DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_DBC,"ptr",$hdbc) DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_ENV,"ptr",$henv) Return SetError(6,0,0) EndIf $hDatabase = DllStructCreate("ptr hdbc;ptr henv") DllStructSetData($hDatabase,"hdbc",$hdbc) DllStructSetData($hDatabase,"henv",$henv) Return SetError(0,0,$hDatabase) EndFunc Func MS_AccessDatabaseDisconnect($hDatabase) Local $SQL_HANDLE_ENV = 1,$SQL_HANDLE_DBC = 2 Local $hdbc = DllStructGetData($hDatabase,"hdbc") Local $henv = DllStructGetData($hDatabase,"henv") SQLDisconnect($hdbc) if @error Then Return SetError(1,0,False) SQLFreeHandle($SQL_HANDLE_DBC,$hdbc) if @error Then Return SetError(2,0,False) SQLFreeHandle($SQL_HANDLE_ENV,$henv) if @error Then Return SetError(3,0,False) Return SetError(0,0,True) EndFunc Func CreateTable($hDatabase,$TableName,$ColumnsListNameTypeSize) Local $SQL_HANDLE_STMT = 3 Local $StatementText = "CREATE TABLE " & $TableName & " (" & $ColumnsListNameTypeSize & ")" Local $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(1,0,False) SQLExecDirect($hStatement,$StatementText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(2,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(0,0,True) EndFunc Func InsertInToTable($hDatabase,$TableName,$ColumnsList,$ValueList) Local $SQL_HANDLE_STMT = 3 Local $StatementText = "INSERT INTO " & $TableName & " (" & $ColumnsList & _ ") VALUES(" & $ValueList & ")" Local $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(1,0,False) SQLExecDirect($hStatement,$StatementText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(2,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(0,0,True) EndFunc Func ColumnsAdd($hDatabase,$TableName,$ColumnsListNameTypeSize) Local $SQL_HANDLE_STMT = 3 Local $StatementText = "ALTER TABLE " & $TableName & _ " ADD " & $ColumnsListNameTypeSize Local $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(1,0,False) SQLExecDirect($hStatement,$StatementText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(2,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(0,0,True) EndFunc Func UpdateTable($hDatabase,$TableList,$ColumnsList,$OperationsList) Local $SQL_HANDLE_STMT = 3 Local $StatementText = "UPDATE " & $TableList & " SET " & _ $ColumnsList & " WHERE " & $OperationsList Local $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(1,0,False) SQLExecDirect($hStatement,$StatementText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(2,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(0,0,True) EndFunc Func DeleteFromTable($hDatabase,$TableName,$OperationsList) Local $SQL_HANDLE_STMT = 3 Local $StatementText = "DELETE FROM " & _ $TableName & " WHERE " & $OperationsList Local $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(1,0,False) SQLExecDirect($hStatement,$StatementText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(2,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(0,0,True) EndFunc Func TableRemove($hDatabase,$TableName) Local $SQL_HANDLE_STMT = 3 Local $StatementText = "DROP TABLE " & $TableName Local $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(1,0,False) SQLExecDirect($hStatement,$StatementText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(2,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(0,0,True) EndFunc Func SelectRecordsGroup($hDatabase,$TableName,$ColumnsList = "",$OperationList = "") ;$ColumnsList Can be empty string "" ;$OperationList Can be empty string "" Local $SQL_HANDLE_STMT = 3 , $SQL_Error = -1 , $SQL_INTEGER = 4 Local $CountStatText = "SELECT COUNT(*) FROM " & $TableName Local $StatementText = "SELECT " if StringLen($ColumnsList) Then $StatementText &= $ColumnsList & " FROM " & $TableName Else $StatementText &= "* FROM " & $TableName EndIf if StringLen($OperationList) Then $StatementText &= " WHERE " & $OperationList $CountStatText &= " WHERE " & $OperationList EndIf Local $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(1,0,0) SQLExecDirect($hStatement,$CountStatText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(2,0,0) EndIf SQLFetch($hStatement) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(3,0,0) EndIf Local $DataStruct = DllStructCreate("INT") , $Col_Num = 1 SQLGetData($hStatement,$Col_Num,$SQL_INTEGER,$DataStruct) if @error Or @extended = $SQL_Error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(4,0,0) EndIf Local $RowsCount = DllStructGetData($DataStruct,1) SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(5,0,0) SQLExecDirect($hStatement,$StatementText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(6,0,0) EndIf Local $ColsCount = SQLGetColsCount($hStatement) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(7,0,0) EndIf Local $ihStatement = 0, $tagSt = "" $tagSt = "PTR HST;INT RSC;INT CSC;WCHAR STT[" & (StringLen($StatementText) + 1) & "]" $ihStatement = DllStructCreate($tagSt) DllStructSetData($ihStatement,"HST",$hStatement) DllStructSetData($ihStatement,"RSC",$RowsCount) DllStructSetData($ihStatement,"CSC",$ColsCount) DllStructSetData($ihStatement,"STT",$StatementText) Return SetError(0,0,$ihStatement) EndFunc Func GetRecordsData(ByRef $hStatement,$hStatementFree = True) Local $SQL_TYPE_DATE = 91 , $SQL_TYPE_TIME = 92 , $SQL_TYPE_TIMESTAMP = 93 Local $SQL_BIT = -7,$SQL_WVARCHAR = -9,$SQL_WLONGVARCHAR = -10,$SQL_WCHAR = -8 Local $SQL_VARBINARY = -3 , $SQL_REAL = 7 , $SQL_GUID = -11 , $SQL_INTEGER = 4 Local $SQL_TINYINT = -6 , $SQL_DOUBLE = 8 , $Row_Num = 4 , $SQL_SMALLINT = 5 Local $SQL_LONGVARBINARY = -4 , $SQL_NUMERIC = 2 , $SQL_HANDLE_STMT = 3 Local $DatType , $ColSize , $ColName , $SQL_BINARY = -2 , $SQL_Error = -1 Local $HandleSta = DllStructGetData($hStatement,"HST") Local $RowsCount = DllStructGetData($hStatement,"RSC") Local $ColsCount = DllStructGetData($hStatement,"CSC") Local $StateText = DllStructGetData($hStatement,"STT") if Not($RowsCount) Or Not($ColsCount) Then Return SetError(1,0,0) Local $ReturnArray[$RowsCount + 3][$ColsCount] While(SQLFetch($HandleSta)) For $Col_Num = 1 To $ColsCount Local $DescribeArray = SQLDescribeCol($HandleSta,$Col_Num) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(2,0,0) EndIf $ColName = $DescribeArray[0] $ColSize = $DescribeArray[1] $DatType = $DescribeArray[2] if ($Row_Num = 4) Then $ReturnArray[0][$Col_Num - 1] = $ColName $ReturnArray[1][$Col_Num - 1] = $ColSize $ReturnArray[2][$Col_Num - 1] = $DatType EndIf Local $VALUES = "",$GetDataerror = 0 Switch $DatType Case $SQL_WCHAR , $SQL_WLONGVARCHAR , $SQL_WVARCHAR SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,0,True) ; $GetSize = True if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(3,0,0) EndIf if @extended <> $SQL_Error Then Local $Length = @extended Local $DataStruct = DllStructCreate("WCHAR[" & ($Length + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(4,0,0) Else $VALUES = DllStructGetData($DataStruct,1) EndIf Else $VALUES = "" ;NULL VALUE EndIf Case $SQL_BINARY , $SQL_VARBINARY , $SQL_LONGVARBINARY SQLGetData($HandleSta,$Col_Num,$SQL_BINARY,0,True) ; $GetSize = True if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(5,0,0) EndIf if @extended <> $SQL_Error Then Local $Length = @extended Local $DataStruct = DllStructCreate("BYTE[" & $Length & "]") SQLGetData($HandleSta,$Col_Num,$SQL_BINARY,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(6,0,0) Else $VALUES = $DataStruct EndIf Else $VALUES = "" ;NULL VALUE EndIf Case $SQL_TYPE_DATE if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(7,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else Local $DataStruct = DllStructCreate("SHORT year;SHORT month;SHORT day") SQLGetData($HandleSta,$Col_Num,$SQL_TYPE_DATE,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(8,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_TYPE_TIME if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(9,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else $DataStruct = DllStructCreate("SHORT hour;SHORT minute;SHORT second") SQLGetData($HandleSta,$Col_Num,$SQL_TYPE_TIME,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(10,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_TYPE_TIMESTAMP if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(11,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else Local $DataStruct = DllStructCreate("SHORT year;SHORT month;" & _ "SHORT day;SHORT hour;SHORT minute;SHORT second") if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(12,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_GUID if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(13,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else Local $DataStruct = DllStructCreate("ulong Data1;" & _ "ushort Data2;ushort Data3;byte Data4[8]") $VALUES = $DataStruct SQLGetData($HandleSta,$Col_Num,$SQL_GUID,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(14,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_TINYINT , $SQL_BIT Local $DataStruct = DllStructCreate("BYTE") SQLGetData($HandleSta,$Col_Num,$SQL_TINYINT,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(15,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_INTEGER Local $DataStruct = DllStructCreate("INT") SQLGetData($HandleSta,$Col_Num,$SQL_INTEGER,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(16,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_REAL Local $DataStruct = DllStructCreate("float") SQLGetData($HandleSta,$Col_Num,$SQL_REAL,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(17,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_DOUBLE,$SQL_NUMERIC Local $DataStruct = DllStructCreate("DOUBLE") SQLGetData($HandleSta,$Col_Num,$SQL_DOUBLE,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(18,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_SMALLINT Local $DataStruct = DllStructCreate("SHORT") SQLGetData($HandleSta,$Col_Num,$SQL_SMALLINT,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(19,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case Else Return SetError(20,0,0) EndSwitch $ReturnArray[$Row_Num - 1][$Col_Num - 1] = $VALUES Next $Row_Num += 1 WEnd if ($hStatementFree) Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) $hStatement = 0 Else SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) EndIf ;$ReturnArray[0][Column Number] = Column Name ;$ReturnArray[1][Column Number] = Column Max Size ;$ReturnArray[2][Column Number] = Column Data Type Return SetError(0,0,$ReturnArray) EndFunc Func EnumRecordsData(ByRef $hStatement,$EnumRecDataProc,$hStatementFree = True) ;---------------------EnumRecDataProc---------------------------------------------------------- ;Func EnumRecDataProc($IsNullValue,$Value,$ColName,$ColFormat,$ColMaxSize,$RowNum,$ColNum) ;return ;True ;Continue ;False ; Stop ; ;return true; ;EndFunc ;---------------------EnumRecDataProc---------------------------------------------------------- Local $SQL_TYPE_DATE = 91 , $SQL_TYPE_TIME = 92 , $SQL_TYPE_TIMESTAMP = 93 Local $SQL_BIT = -7,$SQL_WVARCHAR = -9,$SQL_WLONGVARCHAR = -10,$SQL_WCHAR = -8 Local $SQL_VARBINARY = -3 , $SQL_REAL = 7 , $SQL_GUID = -11 , $SQL_INTEGER = 4 Local $SQL_TINYINT = -6 , $SQL_DOUBLE = 8 , $Row_Num = 4 , $SQL_SMALLINT = 5 Local $SQL_LONGVARBINARY = -4 , $SQL_NUMERIC = 2 , $SQL_HANDLE_STMT = 3 Local $DatType , $ColSize , $ColName , $SQL_BINARY = -2 , $SQL_Error = -1 Local $iReg = DllCallbackRegister($EnumRecDataProc,"int","int;int;int;int;int;int;int") if @error Then Return SetError(1,0,False) DllCallbackFree($iReg) Local $HandleSta = DllStructGetData($hStatement,"HST") Local $RowsCount = DllStructGetData($hStatement,"RSC") Local $ColsCount = DllStructGetData($hStatement,"CSC") Local $StateText = DllStructGetData($hStatement,"STT") if Not($RowsCount) Or Not($ColsCount) Then Return SetError(2,0,False) While(SQLFetch($HandleSta)) For $Col_Num = 1 To $ColsCount Local $DescribeArray = SQLDescribeCol($HandleSta,$Col_Num) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(3,0,0) EndIf $ColName = $DescribeArray[0] $ColSize = $DescribeArray[1] $DatType = $DescribeArray[2] Local $VALUES = "",$GetDataerror = 0 Switch $DatType Case $SQL_WCHAR , $SQL_WLONGVARCHAR , $SQL_WVARCHAR SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,0,True) ; $GetSize = True if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(4,0,0) EndIf if @extended <> $SQL_Error Then Local $Length = @extended Local $DataStruct = DllStructCreate("WCHAR[" & ($Length + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(5,0,0) Else $VALUES = DllStructGetData($DataStruct,1) EndIf Else $VALUES = "" ;NULL VALUE EndIf Case $SQL_BINARY , $SQL_VARBINARY , $SQL_LONGVARBINARY SQLGetData($HandleSta,$Col_Num,$SQL_BINARY,0,True) ; $GetSize = True if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(6,0,0) EndIf if @extended <> $SQL_Error Then Local $Length = @extended Local $DataStruct = DllStructCreate("BYTE[" & $Length & "]") SQLGetData($HandleSta,$Col_Num,$SQL_BINARY,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(7,0,0) Else $VALUES = $DataStruct EndIf Else $VALUES = "" ;NULL VALUE EndIf Case $SQL_TYPE_DATE if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(8,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else Local $DataStruct = DllStructCreate("SHORT year;SHORT month;SHORT day") SQLGetData($HandleSta,$Col_Num,$SQL_TYPE_DATE,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(9,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_TYPE_TIME if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(10,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else $DataStruct = DllStructCreate("SHORT hour;SHORT minute;SHORT second") SQLGetData($HandleSta,$Col_Num,$SQL_TYPE_TIME,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(11,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_TYPE_TIMESTAMP if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(12,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else Local $DataStruct = DllStructCreate("SHORT year;SHORT month;" & _ "SHORT day;SHORT hour;SHORT minute;SHORT second") if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(13,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_GUID if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(14,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else Local $DataStruct = DllStructCreate("ulong Data1;" & _ "ushort Data2;ushort Data3;byte Data4[8]") $VALUES = $DataStruct SQLGetData($HandleSta,$Col_Num,$SQL_GUID,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(15,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_TINYINT , $SQL_BIT Local $DataStruct = DllStructCreate("BYTE") SQLGetData($HandleSta,$Col_Num,$SQL_TINYINT,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(16,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_INTEGER Local $DataStruct = DllStructCreate("INT") SQLGetData($HandleSta,$Col_Num,$SQL_INTEGER,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(17,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_REAL Local $DataStruct = DllStructCreate("float") SQLGetData($HandleSta,$Col_Num,$SQL_REAL,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(18,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_DOUBLE,$SQL_NUMERIC Local $DataStruct = DllStructCreate("DOUBLE") SQLGetData($HandleSta,$Col_Num,$SQL_DOUBLE,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(19,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_SMALLINT Local $DataStruct = DllStructCreate("SHORT") SQLGetData($HandleSta,$Col_Num,$SQL_SMALLINT,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(20,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case Else Return SetError(21,0,0) EndSwitch Local $IsNullValue = ($GetDataerror == $SQL_Error) Local $Return = Call($EnumRecDataProc,$IsNullValue , _ $VALUES,$ColName,$DatType,$ColSize,$Row_Num - 3,$Col_Num) if Not($Return) Then if ($hStatementFree) Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) $hStatement = 0 Else SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) EndIf Return SetError(0,0,True) EndIf Next $Row_Num += 1 WEnd if ($hStatementFree) Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) $hStatement = 0 Else SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) EndIf Return SetError(0,0,True) EndFunc Func SaveStreamFile($hDatabase,$TableName,$ColumnName,$PrimaryKeyName,$PrimaryKeyValue,$FilePath) Local $nBytes Local $ByteStruct = GetBinary($hDatabase,$TableName,$ColumnName,$PrimaryKeyName,$PrimaryKeyValue) if @error Then Return SetError(1,0,False) Local $hFile = _WinAPI_CreateFile($FilePath,1) if Not($hFile) Then Return SetError(2,0,False) Local $Return = _WinAPI_WriteFile($hFile,DllStructGetPtr($ByteStruct),DllStructGetSize($ByteStruct),$nBytes) if Not($Return) Then _WinAPI_CloseHandle($hFile) Return SetError(3,0,False) EndIf _WinAPI_CloseHandle($hFile) Return SetError(0,0,True) EndFunc Func SetStreamFile($hDatabase,$TableName,$ColumnName,$PrimaryKeyName,$PrimaryKeyValue,$FilePath) Local $nBytes Local $FileSize = FileGetSize($FilePath) if @error Then Return SetError(1,0,False) Local $hFile = _WinAPI_CreateFile($FilePath,2,2) if Not($hFile) Then Return SetError(2,0,False) Local $DataStruct = DllStructCreate("BYTE[" & $FileSize & "]") Local $Return = _WinAPI_ReadFile($hFile,DllStructGetPtr($DataStruct),$FileSize,$nBytes) if Not($Return) Then _WinAPI_CloseHandle($hFile) Return SetError(3,0,False) EndIf _WinAPI_CloseHandle($hFile) SetBinary($hDatabase,$TableName,$ColumnName,$PrimaryKeyName,$PrimaryKeyValue,$DataStruct) if @error Then Return SetError(4,0,False) Return SetError(0,0,True) EndFunc Func GetBinary($hDatabase,$TableName,$ColumnName,$PrimaryKeyName,$PrimaryKeyValue) Local $OpList = $PrimaryKeyName & " = " & $PrimaryKeyValue , $nBytes Local $SQL_BINARY = -2 , $SQL_VARBINARY = -3 , $SQL_LONGVARBINARY = -4 Local $hStatement = SelectRecordsGroup($hDatabase,$TableName,$ColumnName,$OpList) if @error Then Return SetError(1,0,0) Local $ReturnArray = GetRecordsData($hStatement) if @error Then Return SetError(2,0,0) Switch $ReturnArray[2][0] Case $SQL_BINARY,$SQL_VARBINARY,$SQL_LONGVARBINARY Local $ByteStruct = $ReturnArray[3][0] Return SetError(0,0,$ByteStruct) Case Else Return SetError(3,0,0) EndSwitch EndFunc Func SetBinary($hDatabase,$TableName,$ColumnName,$PrimaryKeyName,$PrimaryKeyValue,$DataStruct) Local $SQL_VARBINARY = -3 , $SQL_LONGVARBINARY = -4, $SQL_BINARY = -2 , $ColNu = 1 Local $BinarySize = DllStructGetSize($DataStruct),$ParamNu = 1,$SQL_PARAM_INPUT = 1 Local $SQL_C_BINARY = -2 , $SQL_HANDLE_STMT = 3 , $SizeAtOneTime = 1048576 Local $SQL_NEED_DATA = 99 ,$ByteData = DllStructGetPtr($DataStruct) , $InSize = 0 ;SizeAtOneTime = 1048576 bytes // 1 MB Local $hStatement = SelectRecordsGroup($hDatabase,$TableName,$ColumnName) if @error Then Return SetError(1,0,False) EndIf Local $HandleSta = DllStructGetData($hStatement,"HST") Local $DescribeArray = SQLDescribeCol($HandleSta,$ColNu) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Return SetError(2,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Local $ColName = $DescribeArray[0] Local $ColSize = $DescribeArray[1] Local $DatType = $DescribeArray[2] Local $pBinary = ($DatType == $SQL_BINARY Or $DatType == $SQL_LONGVARBINARY Or $DatType == $SQL_VARBINARY) If Not($pBinary) Then Return SetError(3,0,False) Local $HandleSta = GetStmtHandle($hDatabase) if @error Then Return SetError(4,0,False) Local $LenAtExec = SQL_LEN_DATA_AT_EXEC($BinarySize) Local $ParameterValuePtrSt = DllStructCreate("INT") DllStructSetData($ParameterValuePtrSt,1,1) Local $LenAtExecSt = DllStructCreate("INT") DllStructSetData($LenAtExecSt,1,$LenAtExec) Local $Return = DllCall($odbc32,"short","SQLBindParameter","ptr",$HandleSta,"USHORT",$ParamNu, _ "short",$SQL_PARAM_INPUT,"short",$SQL_C_BINARY,"short",$DatType,"LONG" , $BinarySize , "short" , _ 0,"ptr" , DllStructGetPtr($ParameterValuePtrSt) ,"LONG" ,0,"ptr",DllStructGetPtr($LenAtExecSt)) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Return SetError(5,0,0) EndIf Local $StatementText = "UPDATE " & $TableName & " SET " & $ColumnName & " = ? WHERE " & _ $PrimaryKeyName & " = " & $PrimaryKeyValue Local $Return = DllCall($odbc32,"short","SQLExecDirectW","ptr",$HandleSta, _ "wstr",$StatementText,"long",StringLen($StatementText)) if @error Or $Return[0] <> $SQL_NEED_DATA Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Return SetError(6,0,False) EndIf Local $ValuePtrPtrSt = DllStructCreate("PTR") $Return = DllCall($odbc32,"short","SQLParamData","ptr",$HandleSta,"ptr",DllStructGetPtr($ValuePtrPtrSt)) if @error Or $Return[0] <> $SQL_NEED_DATA Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Return SetError(7,0,False) EndIf While (($BinarySize > 0)) $InSize = _Min($SizeAtOneTime,$BinarySize) $Return = DllCall($odbc32,"short","SQLPutData","ptr",$HandleSta,"ptr",$ByteData,"LONG",$InSize) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Return SetError(8,0,False) EndIf $BinarySize -= $InSize WEnd $Return = DllCall($odbc32,"short","SQLParamData","ptr",$HandleSta,"ptr",DllStructGetPtr($ValuePtrPtrSt)) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Return SetError(9,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Return SetError(0,0,True) EndFunc Func SQLDisconnect($ConnectionHandle) Local $Return = DllCall($odbc32,"short","SQLDisconnect","ptr",$ConnectionHandle) if @error Or ($Return[0] <> 0) Then Return SetError(1,0,False) Return SetError(0,0,True) EndFunc Func SQLExecDirect($StatementHandle,$StatementText) Local $TextLength = StringLen($StatementText) Local $Return = DllCall($odbc32,"short","SQLExecDirectW","ptr",$StatementHandle, _ "wstr",$StatementText,"long",$TextLength) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(1,0,False) Return SetError(0,0,True) EndFunc Func SQLFreeStmt($StatementHandle,$Option) Local $Return = DllCall($odbc32,"short","SQLFreeStmt","ptr",$StatementHandle,"ushort",$Option) if @error Or ($Return[0] <> 0) Then Return SetError(1,0,False) Return SetError(0,0,True) EndFunc Func SQLFreeHandle($HandleType,$Handle) Local $Return = DllCall($odbc32,"short","SQLFreeHandle","short",$HandleType,"ptr",$Handle) if @error Or ($Return[0] <> 0) Then Return SetError(1,0,False) Return SetError(0,0,True) EndFunc Func GetStmtHandle($hDatabase) Local $SQL_HANDLE_STMT = 3 Local $hdbc = DllStructGetData($hDatabase,"hdbc") Local $Return = DllCall($odbc32,"short","SQLAllocHandle","short",$SQL_HANDLE_STMT,"ptr",$hdbc,"ptr*",0) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(1,0,0) Local $hStatement = $Return[3] Return SetError(0,0,$hStatement) EndFunc Func SQLFetch($StatementHandle) Local $Return = DllCall($odbc32,"short","SQLFetch","ptr",$StatementHandle) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(1,0,False) Return SetError(0,$Return[0],True) EndFunc Func SQLDescribeCol($StatementHandle,$ColumnNumber) Local $Return = DllCall($odbc32,"short","SQLDescribeColW","ptr",$StatementHandle _ ,"short",$ColumnNumber,"wstr*",0,"short",0,"short*",0,"short*",0,"ULONG*",0, _ "short*",0,"short*",0) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(1,0,0) Local $NameLengthPtr = $Return[5] Local $ColumnNameSt = DllStructCreate("WCHAR[" & ($NameLengthPtr + 1) & "]") $Return = DllCall($odbc32,"short","SQLDescribeColW","ptr",$StatementHandle,"short", _ $ColumnNumber,"struct*",$ColumnNameSt,"short",($NameLengthPtr * 2),"ptr",0,"short*" _ ,0,"ULONG*",0,"short*",0,"short*",0) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(2,0,0) Local $DescribeArray[3] $DescribeArray[0] = DllStructGetData($ColumnNameSt,1) $DescribeArray[1] = $Return[7] $DescribeArray[2] = $Return[6] Return SetError(0,0,$DescribeArray) EndFunc Func SQLGetData($StatementHandle,$Col_Num,$TargetType,$DataStruct,$GetSize = False) if ($GetSize) Then $Return = DllCall($odbc32,"short","SQLGetData","ptr",$StatementHandle _ ,"USHORT",$Col_Num,"short",$TargetType,"ptr",-1,"ULONG",0,"ULONG*",0) Else $Return = DllCall($odbc32,"short","SQLGetData","ptr",$StatementHandle _ ,"USHORT",$Col_Num,"short",$TargetType,"struct*",$DataStruct,"ULONG", _ DllStructGetSize($DataStruct),"ULONG*",0) EndIf if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(1,0,False) Return SetError(0,$Return[6],True) EndFunc Func SQLCOMMIT($hDatabase) Local $hdbc = DllStructGetData($hDatabase,"hdbc") , $SQL_HANDLE_DBC = 2,$SQL_COMMIT = 0 Local $Return = DllCall($odbc32,"short","SQLEndTran","short",$SQL_HANDLE_DBC _ ,"ptr",$hdbc,"short",$SQL_COMMIT) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(1,0,False) Return SetError(0,0,True) EndFunc Func SQLGetColsCount($StatementHandle) Local $Return = DllCall($odbc32,"short","SQLNumResultCols","ptr",$StatementHandle,"short*",0) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(1,0,0) Return SetError(0,0,$Return[2]) EndFunc Func SQL_LEN_DATA_AT_EXEC($length) Local $SQL_LEN_DATA_AT_EXEC_OFFSET = (-100) Return (-($length)+$SQL_LEN_DATA_AT_EXEC_OFFSET) EndFunc1 point -
StringRegExp with flag 2 returns an array1 point
-
This script violates the TOS of EVE Online. Seeing how you do not understand the TOS, here is the excerpt from it that you are violating:1 point
-
Complimenti Certo che siamo tanti italiani che usano autoit! Potremmo unirci e fare un progetto comune1 point
-
User Groups and Rights New Members - New members with that joined the forum within the last day. While in this group there are certain restrictions on the number of posts/PMs that can be made. This is to reduce the impact of spammers. After 24 hours members of this group will be promoted the Members group. Members - Members older than one day but with less than 20 posts. Standard access to the forum. Active Members - Members with more than 20 posts have additional rights No advertsSlightly more generous attachment and PM limitsAccess to the Chat forumAbility to upload files to the Downloads section MVPs - Members who are judged by the community to be helpful, who write and share useful code, who help the development of AutoIt. These users have the same rights as normal members but get a team icon, a little more attachment and PM space, and access to the MVP Chat forum section. Moderators - The forum police. This is not a democracy and each of the mods has their own distinct personality. They have the rights to edit posts, delete posts, ban users, delete users, IP ban, etc. Let the poster beware. Developers - A small group of users with access to the AutoIt source code and who have contributed significantly to the internal development of AutoIt. Some of them are also Moderators. Post Count and Rankings Ranks based on increasing post count are as follows: SeekerWayfarerAdventurerProdigyPolymathUniversalistThese titles are auto-generated and have no relation to actual skill level. Once you reach 300 posts you can change the title to whatever you like.1 point