Jump to content

Recommended Posts

Hi everyone,

I am trying to make a script that runs a query and show it to me to see if everything is right and then decide if I finish it or not so I made a little script as below :

#include <ADO.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>

_ADO_EVENTS_SetUp(True)

_ADO_ComErrorHandler_UserFunction(_ADO_COMErrorHandler)

Local $sDriver = 'SQL Server'
Local $sDatabase = 'DataBase' ; change this string to YourDatabaseName
Local $sServer = 'Localhost' ; change this string to YourServerLocation

Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & ';PWD=' & ';'

;~ Global $Query = _
;~ "BEGIN TRAN" & @CRLF & _
;~ "UPDATE Table" & @CRLF & _
;~ "SET HOUR = 4" & @CRLF & _
;~ "WHERE CUST = 'TEST'" & @CRLF & _
;~ "SELECT * FROM Table" & @CRLF & _
;~ "WHERE CUST = 'TEST'" & @CRLF & _
;~ "ROLLBACK TRAN"

Global $Query = _
"BEGIN TRAN" & @CRLF & _
"SELECT * FROM Table" & @CRLF & _
"WHERE CUST = 'TEST'" & @CRLF & _
"ROLLBACK TRAN"


_Query_Display($sConnectionString, $Query)


Func _Query_Display($sConnectionString, $sQUERY)

; Create connection object
Local $oConnection = _ADO_Connection_Create()

; Open connection with $sConnectionString
_ADO_Connection_OpenConString($oConnection, $sConnectionString)
If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE)

; Executing some query directly to Array of Arrays (instead to $oRecordset)
Local $aRecordset = _ADO_Execute($oConnection, $sQUERY, True)

; Clean Up
_ADO_Connection_Close($oConnection)
$oConnection = Null

; Display Array Content with column names as headers
_ADO_Recordset_Display($aRecordset, 'Query Result')

EndFunc   ;==> _Query_Display

When I ran this script it works great, but when I run the query below :

Global $Query = _
"BEGIN TRAN" & @CRLF & _
"UPDATE Table" & @CRLF & _
"SET HOUR = 4" & @CRLF & _
"WHERE CUST = 'TEST'" & @CRLF & _
"SELECT * FROM Table" & @CRLF & _
"WHERE CUST = 'TEST'" & @CRLF & _
"ROLLBACK TRAN"

It doesn't show anything, when I take those begin and rollback it does what it should but still not showing me anything at all, is there a way around it that you know of?

Thank you.

Share this post


Link to post
Share on other sites
  1. You shouldn't need to wrap a basic SQL Select in a transaction. What's the point in doing that?
  2. When you perform a rollback, your changes get wiped out. So what exactly are you expecting to happen?
  3. Maybe you should check @error following the call to _ADO_Execute

Share this post


Link to post
Share on other sites

1- Is there another way? please explain.

2- I am trying to see the changes happening first, and then decide if I want to roll with them or not on a later step.

3- I did no errors at all.

Share this post


Link to post
Share on other sites

1 - Yes... just drop the BEGIN TRAN and ROLLBACK TRAN from your SQL statement

2 - This may be possible, but you would need to split your SQL statement into multiple requests. Move the ROLLBACK TRAN to it's own statement that gets executed after your reviewed / displayed the results.

Share this post


Link to post
Share on other sites
Posted (edited)

It doesn't show anything even with just the code below:

Global $Query = _
"UPDATE Table" & @CRLF & _
"SET HOUR = 4" & @CRLF & _
"WHERE CUST = 'TEST'" & @CRLF & _
"SELECT * FROM Table" & @CRLF & _
"WHERE CUST = 'TEST'"

Yes the changes were made but nothing was displayed.

Edited by Nas

Share this post


Link to post
Share on other sites

I don't use MS engine(s) but standard SQL requires a semicolumn at the end of each statement.

Otherwise, execute your statements separately.

 


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

I need the query inside the BEGIN TRAN if not it will actually execute before I can see the result.

MS doesn't need the semi column.

Share this post


Link to post
Share on other sites

Try:

BEGIN

UPDATE

SELECT

(here decide what to do, commit or rollback)

ALL in their own query.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
$QUERY = _
"BEGIN TRANSACTION"

_Query_Display($sConnectionString, $QUERY)

$QUERY = _
"UPDATE AdventureWorks2016.HumanResources.Department" & @CRLF & _
"SET GroupName = 'Research % Development'" & @CRLF & _
"WHERE Name = 'Engineering'"

_Query_Display($sConnectionString, $QUERY)

$QUERY = _
"SELECT * FROM AdventureWorks2016.HumanResources.Department" & @CRLF & _
"WHERE Name = 'Engineering'"

_Query_Display($sConnectionString, $QUERY)

$QUERY = _
"ROLLBACK TRANSACTION"

_Query_Display($sConnectionString, $QUERY)

$QUERY = _
"SELECT * FROM AdventureWorks2016.HumanResources.Department" & @CRLF & _
"WHERE Name = 'Engineering'"

_Query_Display($sConnectionString, $QUERY)

The changes were committed and I got this error :

The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.

Share this post


Link to post
Share on other sites

Well, the update now works which is a good thing, but I've no idea why and how you can get this error using this SQL, whatever engine you use.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
8 hours ago, Nas said:
$QUERY = _
"BEGIN TRANSACTION"

_Query_Display($sConnectionString, $QUERY)

$QUERY = _
"UPDATE AdventureWorks2016.HumanResources.Department" & @CRLF & _
"SET GroupName = 'Research % Development'" & @CRLF & _
"WHERE Name = 'Engineering'"

_Query_Display($sConnectionString, $QUERY)

$QUERY = _
"SELECT * FROM AdventureWorks2016.HumanResources.Department" & @CRLF & _
"WHERE Name = 'Engineering'"

_Query_Display($sConnectionString, $QUERY)

$QUERY = _
"ROLLBACK TRANSACTION"

_Query_Display($sConnectionString, $QUERY)

$QUERY = _
"SELECT * FROM AdventureWorks2016.HumanResources.Department" & @CRLF & _
"WHERE Name = 'Engineering'"

_Query_Display($sConnectionString, $QUERY)

The changes were committed and I got this error :

The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.

 

6 hours ago, jchd said:

but I've no idea why and how you can get this error using this SQL, whatever engine you use.

The reason that you got the error message "The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION", in this particular case, is because your _Query_Display() function opens and closes a new connection each time it is executed.  SQL checkpoints, created using BEGIN TRANSACTION statements, only exist within their given connections.  Therefore, when you executed the ROLLBACK, there was no BEGIN TRANSACTION in effect.  The only connection that had a valid BEGIN TRANSACTION was the first one and it was the only statement executed in that connection.

Although it is true that in MSSQL's T-SQL that a semicolon is only necessary in a few conditions, if you are going to batch statements together, you should use GO statements to separate the commands that should logically be executed together.  If/Where you place the GO statements can have effect the result sets returned within the batched statements.

Share this post


Link to post
Share on other sites
1 hour ago, TheXman said:

The reason that you got the error message "The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION", in this particular case, is because your _Query_Display() function opens and closes a new connection each time it is executed. 

Oops, sorry I didn't look at the function itself.  It's indeed a weird (and even completely wrong) way to issue a statement!

@Nas keep up using vanilla ADO_* functions.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Something like this? :

$QUERY = _
"BEGIN TRANSACTION" & @CRLF & _
"UPDATE AdventureWorks2016.HumanResources.Department" & @CRLF & _
"SET GroupName = 'Research 15 Development'" & @CRLF & _
"WHERE Name = 'Engineering'" & @CRLF & _
"Go"

_Query_Display($sConnectionString, $QUERY)

$QUERY = _
"SELECT * FROM AdventureWorks2016.HumanResources.Department" & @CRLF & _
"WHERE Name = 'Engineering'" & @CRLF & _
"Go" & @CRLF & _
"ROLLBACK TRANSACTION"

_Query_Display($sConnectionString, $QUERY)

It didn't work giving me an error: Incorrect syntax near 'Go'.

Share this post


Link to post
Share on other sites
Posted (edited)
35 minutes ago, Nas said:

It didn't work giving me an error: Incorrect syntax near 'Go'.

Sorry, the bit about the GO command was in relation to sqlcmd, osql, or SSMS.

Applications based on the ODBC or OLE DB APIs will receive a syntax error if they try to execute a GO command, as you have seen.

Edited by TheXman

Share this post


Link to post
Share on other sites
1 hour ago, TheXman said:

Sorry, the bit about the GO command was in relation to sqlcmd, osql, or SSMS.

Applications based on the ODBC or OLE DB APIs will receive a syntax error if they try to execute a GO command, as you have seen.

Oh I see, that's too bad, any other Ideas, by the way I tried to put that query between the open connection and close it, still same issue.

Share this post


Link to post
Share on other sites
Posted (edited)

 

I don't have a SQL Server instance installed at the moment so I can't test the script.  Can you run the script below and see if it executes successfully and returns the expected results?  If it fails with any errors, please post the error and the console log.

 

#include <ADO.au3>
#include <Constants.au3>


Global $sDriver           = 'SQL Server'
Global $sDatabase         = 'DataBase' ; change this string to YourDatabaseName
Global $sServer           = 'Localhost' ; change this string to YourServerLocation
Global $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & ';PWD=' & ';'

Global $sQUERY

Global $aRecordset

Global $oConnection


_ADO_EVENTS_SetUp(True)

;Open connection
_ADO_Connection_OpenConString($oConnection, $sConnectionString)
If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to open MSSQL connection.  @error = " & @error)
ConsoleWrite("Connection opened." & @CRLF)

;Begin transaction
_ADO_Execute($oConnection, "BEGIN TRANSACTION", True)
If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to begin transactions.  @error = " & @error)
ConsoleWrite("BEGIN TRANSACTION successful." & @CRLF)

;Update table
_ADO_Execute($oConnection, "UPDATE table SET hour = 4 WHERE cust = 'TEST'", True)
If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to update table.  @error = " & @error)
ConsoleWrite("UPDATE successful." & @CRLF)

;Query table
$aRecordset = _ADO_Execute($oConnection, "SELECT * FROM table WHERE cust = 'TEST'", True)
If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to update table.  @error = " & @error)
ConsoleWrite("SELECT successful." & @CRLF)

;Rollback the update
_ADO_Execute($oConnection, "ROLLBACK TRANSACTION", True)
If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to rollback transactions.  @error = " & @error)
ConsoleWrite("ROLLBACK TRANSACTION successful." & @CRLF)

;Display query result (This is result set captured before rollback)
_ADO_Recordset_Display($aRecordset, 'Query Result')

;Close connection
_ADO_Connection_Close($oConnection)
If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to close MSSQL connection.  @error = " & @error)
ConsoleWrite("Connetion closed." & @CRLF)

 

Edited by TheXman

Share this post


Link to post
Share on other sites

Thanks @TheXman that sounds much more reasonable!

@Nas you typically open an SQL connection at application startup, use it by issuing SQL statements at will, then only close it at program termination, just like you generally do with a GUI.  That's true for any SQL engine I can think of.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Posted (edited)

When I ran your script I got this error : Unable to open MSSQL connection.  @error = 5.

I found that the $oConnection is missing  so I added this line :

Global $oConnection = ObjCreate("ADODB.Connection")
If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to open MSSQL connection.  @error = " & @error)

I was able to open the connection with SQL and then I got this error :

Unable to begin transactions.  @error = 6.

Update:

For some reason it considers every _ADO_Execute as an error, so I removed those lines and it worked like a charm, @TheXman you're the best, can't thank you enough, thank you @jchd I appreciate your help.

#include <ADO.au3>
#include <Constants.au3>

Local $sDriver = 'SQL Server'
Local $sDatabase = 'AdventureWorks2016' ; change this string to YourDatabaseName
Local $sServer = 'Localhost' ; change this string to YourServerLocation
Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & ';PWD=' & ';'

Global $sQUERY

Global $aRecordset

Local $oConnection = ObjCreate("ADODB.Connection")
If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to open MSSQL connection.  @error = " & @error)


_ADO_EVENTS_SetUp(True)

;Open connection
_ADO_Connection_OpenConString($oConnection, $sConnectionString)
If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to open MSSQL connection.  @error = " & @error)
ConsoleWrite("Connection opened." & @CRLF)

;Begin transaction
_ADO_Execute($oConnection, "BEGIN TRANSACTION", True)
ConsoleWrite("BEGIN TRANSACTION successful." & @CRLF)

;Update table
_ADO_Execute($oConnection, "UPDATE HumanResources.Department SET GroupName = 'Research && Development' WHERE Name = 'Engineering'", True)
ConsoleWrite("UPDATE successful." & @CRLF)

;Query table
$aRecordset = _ADO_Execute($oConnection, "SELECT * FROM HumanResources.Department WHERE Name = 'Engineering'", True) ; setting $aRecordset with the result before rolling back
ConsoleWrite("SELECT successful." & @CRLF)

;Rollback the update
_ADO_Execute($oConnection, "ROLLBACK TRANSACTION", True)
ConsoleWrite("ROLLBACK TRANSACTION successful." & @CRLF)

;Display query result (This is result set captured before rollback)
_ADO_Recordset_Display($aRecordset, 'Query Result')

$aRecordset = _ADO_Execute($oConnection, "SELECT * FROM HumanResources.Department WHERE Name = 'Engineering'", True) ; setting $aRecordset with the original result after rolling back

;Display query result (This is result set captured after rollback)
_ADO_Recordset_Display($aRecordset, 'Query Result')

;Close connection
_ADO_Connection_Close($oConnection)
If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to close MSSQL connection.  @error = " & @error)
ConsoleWrite("Connetion closed." & @CRLF)

 

Edited by Nas

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Nas
      Hello Guys,
       
      I am running the Ado example script, if I run this line, it runs without errors :
      Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUser & ';PWD=' & $sPassword & ';' But when I try the windows auth one , it failed everytime :
      Func _Example_MSSQL_WindowsAuthorization() Local $sDatabase = 'AdventureWorks2016' Local $sServer = 'SQLSRV' _Example_5_MSSQL_WinAuth($sServer, $sDatabase, "Select * from Person.Address") EndFunc here is the error :
       
      ADO.au3 v.2.1.16 BETA (1204) : ==> COM Error intercepted !
      $oADO_Error.description is:     Provider cannot be found. It may not be properly installed.
      $oADO_Error.windescription:     Exception occurred.
      $oADO_Error.number is:     80020009
      $oADO_Error.lastdllerror is:     0
      $oADO_Error.scriptline is:     1204
      $oADO_Error.source is:     ADODB.Connection
      $oADO_Error.helpfile is:     C:\Windows\HELP\ADO270.CHM
      $oADO_Error.helpcontext is:     1240655
      By the way, I have 64x windows server 2016 with SQL Server , I already installed the odbc my sql connector, any thought on this will be greatly appreciate it.
    • By argumentum
      #include <SQLite.au3> ;-- When SQLite is compiled with the JSON1 extensions it provides builtin tools ;-- for manipulating JSON data stored in the database. ;-- This is a gist showing SQLite return query as a JSON object. ;-- https://www.sqlite.org/json1.html Example() Func Example() _SQLite_Startup() ; "<your path>\sqlite3.dll", False, 1) ; https://www.autoitscript.com/autoit3/docs/libfunctions/_SQLite_Startup.htm _SQLite_Open() ; ...if you can not run this due to errors, get the latest DLL from https://www.sqlite.org/ If _SQLite_Exec(-1, "CREATE TABLE users (id INTEGER PRIMARY KEY NOT NULL, full_name TEXT NOT NULL, email TEXT NOT NULL, created DATE NOT NULL );") Then Return 4 If _SQLite_Exec(-1, 'INSERT INTO users VALUES ' & _ '(1, "Bob McFett", "bmcfett@hunters.com", "32-01-01"),' & _ '(2, "Angus O''Vader","angus.o@destroyers.com", "02-03-04"),' & _ '(3, "Imperator Colin", "c@c.c", "01-01-01");') Then Return 5 ; -- Get query data as a JSON object using the ; -- json_group_object() [1] and json_object() [2] functions. _SQLite_GetTable2d_ArrayToConsole("SELECT" & _ " json_group_object(" & _ " email," & _ " json_object('full_name', full_name, 'created', created)" & _ " ) AS json_result" & _ " FROM (SELECT * FROM users WHERE created > ""02-01-01"");") ; {"bmcfett@hunters.com":{"full_name":"Bob McFett","created":"32-01-01"},"angus.o@destroyers.com":{"full_name":"Angus O'Vader","created":"02-03-04"}} ; -- Get query data as a JSON object using the ; -- json_group_array() function to maintain order. _SQLite_GetTable2d_ArrayToConsole("SELECT" & _ " json_group_array(" & _ " json_object('full_name', full_name, 'created', created)" & _ " ) AS my_json_result_OrAnythingReally" & _ " FROM (SELECT * FROM users ORDER BY created);") ; [{"full_name":"Imperator Colin","created":"01-01-01"},{"full_name":"Angus O'Vader","created":"02-03-04"},{"full_name":"Bob McFett","created":"32-01-01"}] ;-- Links ;-- [1] https://www.sqlite.org/json1.html#jgroupobject ;-- [2] https://www.sqlite.org/json1.html#jobj ; example found at https://gist.github.com/akehrer/481a38477dd0518ec0086ac66e38e0e2 EndFunc ;==>Example Func _SQLite_GetTable2d_ArrayToConsole($sSQL, $hDB = -1) Local $aResult, $iRows, $iColumns If _SQLite_GetTable2d($hDB, $sSQL, $aResult, $iRows, $iColumns) Then ConsoleWrite("! SQLite Error: " & _SQLite_ErrCode($hDB) & @CRLF & "! " & _SQLite_ErrMsg($hDB) & @CRLF) Else _SQLite_Display2DResult($aResult) EndIf ConsoleWrite(@CRLF) EndFunc ;==>_SQLite_GetTable2d_ArrayToConsole Based on this example, you can build your own query. 
      The code has all the explanations.
      Enjoy  
    • By argumentum
      $sQueryUpdateTime = "select intUpdateTime from tblStudies " . $where . " ORDER BY intUpdateTime DESC limit 1"; $rs = mysqli_query($conn, $sQueryUpdateTime); $row = mysqli_fetch_assoc($rs); the above used to take 300+ ms. to query. Then I set it as index and takes 30 ms. Cool.
      $sQuery = "select * from tblStudies " . $where . " ORDER BY StudyDate DESC limit $offset,$rows"; // takes 30 ms. on the indexed int $sQuery = "select * from tblStudies " . $where . " ORDER BY StudyDate DESC , PatientName ASC limit $offset,$rows"; // takes 300 ms. due to "PatientName" been a text field, even as I did index it So my observation is that "PatientName" takes a long time to sort, even tho "$rows = 20". Sorting text in 20 rows should be fast.
      ..tho, I find that any 2nd argument in the ORDER BY is just slow.
      Is there a way to query this in a way to have a faster result back ?
      Thanks
      PS: added ADD INDEX `StudyDate_2` (`StudyDate`, `PatientBirthDate`) USING BTREE;  and searched by those two with not much speed change ( StudyDate and PatientBirthDate are integer ).
    • By buymeapc
      Hello,
      I was looking for a way to use the CLR functions to check a SQL 2016 database state, but I've been unable to find an example that I can get to work. Any help would be appreciated. Here's what I have, which always errors when I try to set the connection string and I'm not sure why. Thanks!
      #include ".\Includes\CLR.au3" #include ".\Includes\CLR Constants.au3" JustATest() Func JustATest() Local $oAssembly = _CLR_LoadLibrary("System.Data") ConsoleWrite("$oAssembly: " & IsObj($oAssembly) & @CRLF) Local $oSQLConn = _CLR_CreateObject($oAssembly, "System.Data.SqlClient.SqlConnection") ConsoleWrite("$oSQLConn: " & IsObj($oSQLConn) & @CRLF) $oSQLConn.ConnectionString = "Server=serverip;Database=dbname;UID=user;PWD=aaaa;" $oSQLConn.Open EndFunc Edit: I am using ptrex's CLR UDF from here:
    • By nooneclose
      Good morning, I am trying to figure out if it is possible to check if these invoice lines exist or not. 
      Here are the table and column name: INVOICELINE.INVOICELINENUM (a required field if created)
      Here is a picture of what I am talking about. (Do not worry about security. the picture is from a demo test site so all information is fake)
       
      is there any way to check if these fields exist or not? (they do not exist unless the user clicks on "New Row")
      Example: line 11 does not exist right now. How would I go about to see if it did or not? 
      This is what I have so far:
      SELECT DISTINCT iv.invoicenum, iv.description FROM invoice AS iv JOIN invoiceline AS ivl ON iv.invoicenum = ivl.invoicenum AND iv.siteid = ivl.siteid /* = 'nothing' and yet somehow not null? */ WHERE iv.invoicenum NOT IN (SELECT invoicelinenum FROM invoiceline WHERE invoicelinenum IS NOT NULL) I get 0 results where I should get more than 0. 
×
×
  • Create New...