Leaderboard
Popular Content
Showing content with the highest reputation on 11/12/2014 in all areas
-
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 -
You might have fun trying the binary GCD variant and Knuth-Shönage. For those not too faint-hearted, I higly recommend the evaluation of the traditional euclidean algorithm discussed by Knuth in TAOCP vol 2. Also the euclidean algorithm is important to music. Disclaimer: I'm a big big big fan of the magic of the extended euclidean algorithm for too many reasons to expose here.1 point
-
The macro option should be able to work for the bolding part, since they are unique wordings that only appear in that specific section. I can also simply attach to the current open word document and run the macro with a click of a single hotkey. Took some time to find the macro function though as they did away with the old one to replace it with something similar. Thanks for the help1 point
-
Hyflex, The problem is not AutoIt, it is Au3Check - as a quick search of the forum for the many recent "missing separator" threads would have shown. The solution is to use Tidy on the UDF script to add the missing spaces between the function parameters - or update your SciTE4AutoIt3 to the latest Beta where Au3Check no longer regards that problem as an error. As to TheSaint's point about modifying UDFs by removing ByRef - I am in complete agreement with his warning as doing something like that can completely alter the manner in which the code deals with the parameter, quite possibly making the code unusable (see the Variables - using Global, Local and ByRef tutorial in the Wiki to see why). So please be very careful about doing so. M231 point
-
Easiest route...have a common dir...in that dir, add user dirs. Have each session create files in their specific dir, with whatever your message is. Have your base script loop for, and read those files, and do whatever is needed. Or, just have them all output to one dir, as an ini|xml|etc, and logically set values to know where it's coming from, and what to do.1 point
-
How to perform shorcut key (Ctrl C + Crtl V)
232showtime reacted to JLogan3o13 for a topic
Is there a reason you need to use a shortcut key rather than using the built in FileRead or FileReadLine functions?1 point -
Getting Word from Title
sobert reacted to JLogan3o13 for a topic
For the most part, yes you can. Given a window title of My Awesome Notepad Example.txt, you could do something like this: $sTitle = WinGetTitle("[CLASS:Notepad]", "") ;get the full title $aSplit = StringSplit($sTitle, " ") ;split the title by spaces ConsoleWrite($aSplit[4] & @CRLF) ;get the fourth element If you're unable to get the class of the window, try using text inside the window (the second parameter in WinGetTitle).1 point -
Predictive Combo Box
232showtime reacted to Melba23 for a topic
Jewtus, You need to use _GUICtrlComboBox_AutoComplete like this: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIComboBox.au3> Global $array_1[10] = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"] Global $array_2[5] = ["alpha", "beta", "gamma", "delta", "epsilon"] $hGUI = GUICreate("Example", 500, 200) $cCombo_Number = GUICtrlCreateCombo("", 50, 50, 200, 20) $cCombo_Alpha = GUICtrlCreateCombo("", 50, 100, 200, 20) $a = "" For $i = 0 To UBound($array_1) - 1 $a &= $array_1[$i] & "|" Next GUICtrlSetData($cCombo_Number, $a) $a = "" For $i = 0 To UBound($array_2) - 1 $a &= $array_2[$i] & "|" Next GUICtrlSetData($cCombo_Alpha, $a) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _Edit_Changed($hControl) ; <<<<<<<<<<<<<<<<<<<<< _GUICtrlComboBox_AutoComplete($hControl) ; <<<<<<<<<<<<<<<<<<<<< EndFunc ;==>_Edit_Changed Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word $iCode = BitShift($iwParam, 16) ; Hi Word Switch $iCode Case $CBN_EDITCHANGE Switch $iIDFrom Case $cCombo_Number _Edit_Changed($cCombo_Number) ; <<<<<<<<<<<<<<<<<<<<< Case $cCombo_Alpha _Edit_Changed($cCombo_Alpha) ; <<<<<<<<<<<<<<<<<<<<< EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND M231 point -
paexec, or create, and then run, a scheduled task to run as the logged in user. I also like having a tcpip listener...I'll add it to the startup folder of the user(s)...then the service tells the listener what to do. We do a similar thing to run regression suites.1 point