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

Generate a fresh DOM element when a particular height threshold is achieved, utilizing a portion of the previous DOM element's content

Update: 27th December 2016 The heading has been modified because any DOM element can be the target, whether it is a <p> element or not. Additional information has been provided about the tools being used and the desired outcome. Are there nativ ...

Experiencing difficulty receiving a full response from an ajax-php request displayed in a div

Having trouble getting a response in a div from an ajax request triggered by an onclick event in a form and a PHP page. Here's the code: <html> <head> <script language="javascript"> function commentRequest(counter) { new Ajax. ...

What is the best way to transform an array of objects in JavaScript?

I'm working with an array of objects that I need to transform into a table by pivoting the data. In other words, I am looking to generate a new array of objects with unique titles and nested arrays of key-value pairs. Can someone please assist me in a ...

Merging object keys and values from JSON arrays based on their keys, using JavaScript

Is there a way to merge object keys' values from JSON arrays based on their key? json1 = [ {key:'xyz', value:['a','b']}, {key:'pqrs', value:['x','y']} ] json2 = ...

Using AJAX to dynamically populate PHP form inputs from HTML

I'm trying to create a simple HTML form where users can input their information and have it sent to a PHP file using JavaScript with AJAX. However, I'm encountering an issue where the values from the form are not being included in the email that ...

The whitespace issue stems from the div element __next-build-watcher generated by next js and usecontext

There's a notification bar at the bottom of my page that lets the user know when their email has been sent. This bar is generated using useContext in React/Next.js. To see the code, check out this Codebox link: Code However, I've noticed there ...

Display just a couple of programs per category

My database has a table called software with columns (id_software, software_name, category). Can someone help me write an SQL query to display only 2 software entries for each category? For instance, I would like the output to look like this: |id_softw ...

Applying a translucent layer of color to a jpeg image to create a subtle background effect

I am attempting to create a semi-transparent, solid background color on top of an <img> tag, while still showing the original image underneath at the same ratio and size. Below is a snippet of the code I am working with (let me know if you need more ...

What is the best way to integrate HTML code within a JavaScript function?

I need the HTML code to execute only when a specific condition in JavaScript is met. Here is the JavaScript code: <script type="text/javascript"> $(document).ready(function () { if(window.location.href.indexOf("index.php") > -1) { ...

Tips for achieving expansion of solely the clicked item and not the whole row

I am trying to create a card that contains a cocktail recipe. The card initially displays just the title, and when you click on a button, it should expand to show the full menu and description. The issue I'm facing is that when I click on one element, ...

What are the steps to resolving an Unhandled promise rejection error in a Node.js application?

I encountered an error message that I need help resolving: I am faced with an unhandled promise rejection. This issue likely occurred due to throwing inside an async function without a catch block, or rejecting a promise without handling it using .catch( ...

Handling mousewheel events for child elements and their parent element

I developed a custom jQuery plugin that replaces the default scrollbar with my own, managing mousewheel and bar dragging events. The issue arises when I place content containing my custom scrollbar within another content also using my scrollbar. When I sc ...

When an import is included, a Typescript self-executing function will fail to run

Looking at this Typescript code: (()=> { console.log('called boot'); // 'called boot' })(); The resulting JavaScript is: (function () { console.log('called boot'); })(); define("StockMarketService", ["require", "exp ...

Positioning Multi-level Drop Down Div in Javascript - How to do it efficiently?

I'm currently working on a horizontal menu using CSS and JavaScript with multiple levels. I've implemented a toggle function to show the submenu container, but it's causing the links below it to be pushed down. Is there a way to make the dis ...

Craft an engaging and dynamic Image map with SVG technology to elevate responsiveness and interactivity

I'm currently working on a website and I need to create two clickable sections on the home page. Each section will lead to a different specialization of the company. To achieve this, I decided to use a square image split into two right-angled triangle ...

Validate the checkbox with Vuelidate only when the specified property is set to true

I have a website login form where users may need to check a specific checkbox before logging in. Here is part of the Vue component code that handles this functionality: <script setup lang="ts"> import {ref, defineProps} from 'vue&a ...

Is there a way to update my profile picture without having to constantly refresh the page after uploading it?

Here is the code for my profile page. I am considering using a callback along with another useEffect function, but I'm unsure. Please help me in finding a solution. For now, let's ignore all the code related to deleting, saving, and handling ingr ...

Search the database to retrieve a specific value from a multi-dimensional array

My database is structured as shown in the image below: https://i.sstatic.net/Flne8.png I am attempting to retrieve tasks assigned to a specific user named "Ricardo Meireles" using the code snippet below: const getTasksByEmployee = async () => { se ...

I'm searching for a universal guidebook on creating web page layouts

After 5 years of creating webpages, I have realized that my sites tend to have a nostalgic 1995 internet vibe. Despite being a C# programmer with knowledge in HTML, JavaScript, and CSS, my design skills could use some improvement. Is there a quick referenc ...

When assigning JSON to a class object, the local functions within the class became damaged

This is a demonstration of Object Oriented Programming in JavaScript where we have a parent Class called Book with a child class named PriceDetails. export class Book { name: String; author: String; series: String; priceDetails: Array<Price> ...