Generic Function to Execute different SQL operations
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Generic Function to Execute different SQL operations
Hi ,
Is it possible to have a single function that would handle most of the SQL queries. for now , i have seperate SQL function for different type of operations.
for example
- function that would just execute select
- function that would just handle insert
- function that would just handle delete
- function that would just handle Update
- function that would return count of records ,e.g count(*)
I would like to write something generic that would handle all of the above operations
Your help is appreciated
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually, as a matter of fact, you can. I have a script extension I've developed that will do that. Basically, if you can write what you want as Transact-SQL, you should be able to execute it using that extension.
If you don't want to use the extension, check out https://support.smartbear.com/testcomplete/docs/testing-with/advanced/working-with-external-data-sou.... The examples that are included have hardcoded strings as the SQL query. Replace those strings with a parameter from the function and you should be able to send any SQL query you want to to the function.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi ,
Thanks a lot. Do you happened to have code using all these function calls ?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here's an example:
//The following function can be included in any project but it only ever needs to be run the first time to set up the desired settings function SQLOptions(){ SQLUtilities.SetSQLType = 'MSSQL'; //Can be either MSSQL or MYSQL_351 SQLUtilities.SetSQLSecurityType = 'INTEGRATED'; //Can be either INTEGRATED or PROMPT } //Now, if I want to run an SQL query against my database where I log the street address for all addresses in Pennsylvania, USA function getPAStreetAddresses() { var mySQLQuery; var myRecords; SQLUtilities.DatabaseName = 'MyDatabase'; SQLUtilities.SQLServerName = 'MyServer'; SQLUtilities.SQLUserName = 'myusername'; //This is not necessary since I'm using integrated security. Provided in example to allow for editing and adaptation SQLUtilities.SQLPassWord = 'mypassword'; //This is not necessary since I'm using integrated security. Provided in example to allow for editing and adaptation mySQLQuery = SQLUtilities.NewSQLQuery('SELECT * FROM ADDRESSES WHERE STATE = :STATE and COUNTRY = :COUNTRY', {STATE: 'PA', COUNTRY: 'USA'}, false); mySQLQuery.open(); myRecords = mySQLQuery.execute(); while (!myRecords.EOF) { Log.Message('Street Address: ' + myRecords.Fields.Item('STREETADDRESS').Value); myRecords.MoveNext(); } mySQLQuery.closeAndNull; }
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
