Forum Discussion
There's still some problem with passing in the parameters object. I'm working on figuring that out so there's an aspect of it that's still not working.
For those of you who are curious... and perhaps can help... the problem is here:
function queryObject(query, parameters) { this.queryString = query; if (parameters == undefined) { parameters = []; } this.parameterArray = []; for (parameter in parameters) { this.parameterArray.push({name: parameter, value: parameters[parameter]}); } } function getSQLFromFile(filePath) { return aqFile.ReadWholeTextFile(filePath, aqFile.ctANSI); } function open() { //Opens the connection on the query object and sets it as the Active Connection on the command object property this.localConnection.Open(); this.localCommand.CommandObject.ActiveConnection = this.localConnection; } function closeAndNull() { //Closes the connection on the object and sets the connection and command objects to null to free up memory space if (this.localConnection.State != 0) { this.localConnection.Close(); } this.localConnection = null; this.localCommand = null; } function execute() { //assigns the query to the command text, parses it for parameters, and then executes the query as a command, returning any recordset this.localCommand.CommandText = this.queryObject.queryString; this.localCommand.Parameters.ParseSQL(this.localCommand.CommandText, true); for (var i = 0; i < this.queryObject.parameterArray.length; i++) { this.localCommand.Parameters.ParamByName(this.queryObject.parameterArray[i].name).Value = this.queryObject.parameterArray[i].value; } return this.localCommand.Execute(); } function sqlQuery(sqlString, parameters, stringIsFile) { try { if (stringIsFile == undefined) { stringIsFile = false; } var localObject = {}; var queryString; stringIsFile ? queryString = getSQLFromFile(sqlString) : queryString = sqlString; localObject.queryObject = new queryObject(sqlString, parameters); localObject.localConnection = ADO.CreateConnection(); localObject.localConnection.ConnectionString = getConnectionString(); localObject.localCommand = ADO.CreateADOCommand(); localObject.open = open; localObject.execute = execute; localObject.closeAndNull = closeAndNull; return localObject; } catch (exception) { Log.Error('Could not execute sqlQuery: ' + exception.message, exception.stack); } }
Specifically, the bolded loop is never getting hit. Without this, if you want to run a query similar to what I have in the readme in my repository, we get an error that the parameters object of localCommand is not set up properly and the whole thing errors out. As far as I can tell, for (<property> in <object>) should still work just fine in JScript, but for some reason, the enumeration of the properties is not happening.
So... if y'all have any ideas, I'm open. I'll still be working on this but the extension should work as is if you handle the parameters of the sql query externally of the objects and just pass in the string and a blank params object.
Related Content
Recent Discussions
- 53 minutes agoSubhraDas
- 20 hours agotramuntana