How to achieve the functionality of ocibindbyname in JavaScript

I am currently utilizing an HTA page that is coded in JavaScript to monitor various Oracle tables.

My goal is to optimize the Oracle query caching by using bind variables, similar to how I implemented it in a PHP environment with this code:

$sql = "select m1_master from CEDWORK.hd_anag where account = :utente";
$s = OCIParse($c, $sql);
ocibindbyname($s, ":utente", $utente);
if ( OCIExecute($s, OCI_DEFAULT) == false ){
   gsterr($sql, "record not found");
}
 while (ocifetch($s)) {
       $codmec = OCIResult($s, "M1_MASTER");
}

For the JavaScript in the HTA file, I used the following code snippet:

function test1(idUtente){
  var adOpenDynamic = 2
  var adLockOptimistic = 3
  var conn_str = "Provider=OraOLEDB.Oracle;Password=xxxx;Persist Security Info=True;User ID=xxxx;Data Source=sgo01";
 var conn = new ActiveXObject("ADODB.Connection")
 conn.open(conn_str)
 var rsPass = new ActiveXObject("ADODB.Recordset");
 var arrPass = new Array();
 var rs2arr = new Array();
 var  SQLpass = "SELECT  cod_operatore, a.cognome, a.nome, a.account, m1_master ";   
 SQLpass += "from cedwork.hd_operatori a, cedwork.hd_anag b " ;
 SQLpass += "where a.account = b.account " ;
 SQLpass += "and  a.account = '" + idUtente + "'" ;

 rsPass.open(SQLpass, conn, adOpenDynamic, adLockOptimistic);
 alert(rsPass.fields("m1_master").value);
 rsPass.close();

}

I am looking to replace the "idUtente" variable with a bind variable in JavaScript, but I have been unable to find the correct syntax for doing so.

Thank you for any assistance, Marco

Answer №1

Just a heads up - I haven't personally used ADODB before, but after some careful searching on "ADODB," "prepared statements," and "bind variables," I found some helpful information from:

This information led me to the following solution:

var conn = new ActiveXObject("ADODB.Connection");
var cmd  = new ActiveXObject("ADODB.Command");
var rs   = new ActiveXObject("ADODB.Recordset");
conn.open( "Provider=OraOLEDB.Oracle;Password=xxxx;Persist Security Info=True;"
           + "User ID=xxxx;Data Source=sgo01" );
cmd.ActiveConnection = conn;
cmd.CommandText = "SELECT  cod_operatore, a.cognome, a.nome, a.account, m1_master "
                  + "FROM cedwork.hd_operatori a "
                  + "INNER JOIN cedwork.hd_anag b "
                  + "ON ( a.account = b.account ) "
                  + "WHERE a.account = ?";
cmd.Parameters.Append(
  cmd.CreateParameter( "id", adChar, adParamInput, 20, idUtente )
);
rs = cmd.Execute();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the method to prevent the label from closing in the MUI 5 datepicker?

Is there a method to prevent the Material 5 Datepicker from closing when there's a label but no value? Current Scenario: Current Desired Outcome: Expected Sample Code: <LocalizationProvider dateAdapter={AdapterDayjs}> <DatePicker lab ...

Trouble accessing onclick function

My dataSend AJAX function is not being called when I use the onclick event. I have checked in the Inspector of my browser and confirmed that the click handler is attached to it. However, when I set a breakpoint in the function using the Debugger, it never ...

Concealing the URL Once Links are Accessed

I have a Movie / TV Shows Streaming website and recently I've noticed visitors from other similar sites are coming to my site and copying my links. Is there a way to hide the links in the address bar to make it more difficult for them to access my con ...

What is the most effective method for accurately tallying the number of matches in a Datalist using the Input value as a reference

I have set up a datalist element with an associated input element for autocompletion in modern browsers: HTML code <input type="search" id="search" list="autocomplete" /> <datalist id="autocomplete"> <option value="c++" /> < ...

Adding items to an array retrieved from JSON

My goal is to merge 3 different Facebook feeds into a single object called "item." Each item includes the post creation time and the JSON data itself. However, I'm facing an issue where only 5 items are displayed when I check the log, even though ther ...

An effective way to determine the size of a browser through javascript

In an effort to enhance the responsiveness of a website, I have included the following code snippet on one of my pages: document.write(screen.width+'x'+screen.height); However, I am encountering an issue where the code displays my screen resolu ...

How can I display SQL results in a Jade page using Node, Express, and MySQL?

My application built with Node.js and Express is connected to a MySQL database for monitoring purposes. The code structure is as follows: In the Node file: app.get('/banners', function(req,res){ connection.query("SELECT * FROM banner_store_ ...

Tips for choosing multiple files with the Ctrl key in a list item element:

We have decided to create our own browsing functionality due to the limitations of the existing HTML browse feature. While using the HTML browse, we can only select multiple files by pressing the Ctrl key, and we want to replicate this feature in our custo ...

Is it possible to remove certain 'css-' class names that MUI automatically applies to its components? (Using Next JS and MUI)

After successfully migrating my create-react-app project to Next JS using the latest version (12.1.0) and following the migration guide at https://nextjs.org/docs/migrating/from-create-react-app, I encountered an unexpected issue. Despite still using MUI a ...

What is the best method for loading multiple HTML files into a Div container?

Recently, I made the decision to improve the look of an online manual I have been working on for my company by incorporating Bootstrap. The manual is structured with a tree-view that contains titles linking to HTML files with information and CSS stylesheet ...

Encountering a NaN result while attempting to incorporate a drop-down menu into a newly developed macro calculator

Before the calculator was functioning smoothly, but as soon as I included the activity level selection from the dropdown menu, things took a turn. The expected output is supposed to be the result of multiplying the user's chosen activity level by the ...

"Hover over the image to see it enlarge and reveal text displayed on top using CSS3

I have been working on creating a responsive image page for my website. I've managed to make the images responsive and centered, no matter the size of the browser window. However, I encountered an issue where when I hover over an image, it enlarges a ...

Trigger an Event Handler only after ensuring the completion of the previous event handling

When attaching an event handler to a callback, it is important to consider the timing of the actions. For example: $("someSelector").on('click',callBackHandler); function callBackHandler(){ //Some code $.ajax({ //Ajax call with succe ...

When attempting to use focusin/focusout, I encountered the following error: Uncaught TypeError - The property 'addEventListener' cannot be read from null

When attempting to utilize the DOM events focusin/focusout, I encountered an error: Uncaught TypeError: Cannot read property 'addEventListener' of null. The issue seems to be originating from main.js at lines 18 and 40. I am using Chrome as my b ...

Magical Stylist - Eradicate Indicators while Preserving Labeling

Recently, I've been experimenting with the Google styling wizard in an effort to remove markers while retaining labels for businesses. My objective is to eliminate the marker icons but still display the text labels such as "Jimmy Johns," "Boone Saloon ...

How Keyof can render an object undefined and prevent accurate verification

Encountering TS2532 error: Object is possibly 'undefined' while attempting to access an object's value by dynamically selecting the key. TypeScript seems to be restricting me from checking the field values, and I'm unsure of the underly ...

The message "Error: Unknown custom element: <router-view> - have you properly registered the component?" is prompting for a solution

Even though the name is correctly capitalized in all my component instances, I am still encountering an error. After researching similar issues online, it appears that the problem usually revolves around naming discrepancies. However, I have double-checked ...

Getting the specific information you need from a JSON object in Angular 2

Struggling to extract specific data from a JSON file with nested objects like this: { "results" : [ { "address_components" : [ { "long_name" : "277", "short_name" : "277", "types" : [ "street_number" ] ...

Tips for keeping a login session active on multiple tabs

As I am in the process of developing a website, one issue I am facing is determining the most effective method to maintain user login sessions. Currently, I am utilizing Html5 web storage known as "session storage" to keep track of whether a user is logged ...

Guide on incorporating markdown in an ejs template

As I am planning to create a small blog using Express, EJS, and Markdown, I encountered an issue when trying to load Markdown on the page. Here is what I saw: Here's my code snippet: <!DOCTYPE html> <html lang="pl"> <head> &l ...