Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #15040 > unrolled thread

Accessing SQL Server from Browser Safely and Portably

Started byGene Wirchenko <genew@ocis.net>
First post2012-07-13 14:21 -0700
Last post2012-07-14 21:40 +1000
Articles 4 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  Accessing SQL Server from Browser Safely and Portably Gene Wirchenko <genew@ocis.net> - 2012-07-13 14:21 -0700
    Re: Accessing SQL Server from Browser Safely and Portably Ross McKay <au.org.zeta.at.rosko@invalid.invalid> - 2012-07-14 09:27 +1000
      Re: Accessing SQL Server from Browser Safely and Portably Gene Wirchenko <genew@ocis.net> - 2012-07-13 21:18 -0700
        Re: Accessing SQL Server from Browser Safely and Portably Ross McKay <au.org.zeta.at.rosko@invalid.invalid> - 2012-07-14 21:40 +1000

#15040 — Accessing SQL Server from Browser Safely and Portably

FromGene Wirchenko <genew@ocis.net>
Date2012-07-13 14:21 -0700
SubjectAccessing SQL Server from Browser Safely and Portably
Message-ID<ih31085fcn1hp61c1tdqclduk7lf7lpr1n@4ax.com>
Dear JavaScripters:

     I wish to access an SQL Server database.  I want this to work
with more than just IE so the use of ActiveX on the browser side is
out.  On the server-side, I do not care for now though if it is
avoided there, too, fine.

    I want something like this use case (to start):

User:
         Specify that Client ABC's row is to be retrieved.

Browser-Side:
         Receive user's request.
         Open XHR connection.
         Send request to get Client row for Client "ABC".

Server-Side:
         Receive request.
         Translate it (this example) to "execute GetClientRow 'ABC'".
         Send that translation to SQL Server.

SQL Server:
         Execute the SP and return the results.

Server-Side:
         Get the results.
         Send them back to the browser.

Browser-Side:
         Get the results.
           ??? What format?  And how do I access the data?
         Fill in the DE form with retrieved data.
         Do data entry stuff.

     I repeat: I do not want ActiveX on the browser-side since I want
this to work with more than IE.

     I thought it should be easy to find some basic code for this, but
no such luck.

     The above use case implies changing the data and updating the row
and naturally, I want to be able to do more.  Being able to do the
above would be a good start.  My opposite number is unlikely to allow
adding additional software (Node.js, for example) on the server.

     How do I do this?

Sincerely,

Gene Wirchenko

[toc] | [next] | [standalone]


#15046

FromRoss McKay <au.org.zeta.at.rosko@invalid.invalid>
Date2012-07-14 09:27 +1000
Message-ID<cta108pdepv8u737pmv4mdhdhpiemb98so@4ax.com>
In reply to#15040
On Fri, 13 Jul 2012 14:21:23 -0700, Gene Wirchenko wrote:

>[...]
>Browser-Side:
>         Get the results.
>           ??? What format?  And how do I access the data?

Depends on how you want to deal with it.

JSON -- you get an object that you can directly manipulate in
JavaScript.

HTML -- you can just replace an element (and its children) with a new
one (and its children).

text -- if all you want is new text for contents of an element, or even
a simple yes/no true/false type response.

There's also XML, but then you need to deal with that in your script,
and unless there's other consumers of your AJAX interface, I'd go with
JSON instead.

>[...]
>     I thought it should be easy to find some basic code for this, but
>no such luck.

http://google.com/search?hl=en&q=php%20mysql%20ajax%20tutorial

Those are for PHP, and for MySQL, but the essence is the same in
whichever server-side scripting language.

>[...]
>     The above use case implies changing the data and updating the row
>and naturally, I want to be able to do more.  Being able to do the
>above would be a good start.  My opposite number is unlikely to allow
>adding additional software (Node.js, for example) on the server.

So, what is your server, and what is available to run on it without
upsetting your opposite number? e.g. Linux/Unix vs Windows, Classic ASP
and .NET vs PHP, Ruby, Python... these things change your approach, so
tell us more.
-- 
Ross McKay, Toronto, NSW Australia
Man's Prayer:
"I'm a man, but I can change.
 If I have to.
 I guess." - Red Green

[toc] | [prev] | [next] | [standalone]


#15049

FromGene Wirchenko <genew@ocis.net>
Date2012-07-13 21:18 -0700
Message-ID<6ds108hv0h4cqram4av59c70ikf9kcenqf@4ax.com>
In reply to#15046
On Sat, 14 Jul 2012 09:27:24 +1000, Ross McKay
<au.org.zeta.at.rosko@invalid.invalid> wrote:

>On Fri, 13 Jul 2012 14:21:23 -0700, Gene Wirchenko wrote:
>
>>[...]
>>Browser-Side:
>>         Get the results.
>>           ??? What format?  And how do I access the data?
>
>Depends on how you want to deal with it.

     I would like to fill a form with the values.  I would need each
column name and value.  The values might need some escaping; if so,
what?  The values might need some formatting; I can handle that.

     ANy of the suggestions below might work for me, but I do not know
how to get any of them to work.  Basic URLs would help.  If I can get
a basic case going, I will probably be off to the races.  Currently, I
am spinning.

>JSON -- you get an object that you can directly manipulate in
>JavaScript.

>HTML -- you can just replace an element (and its children) with a new
>one (and its children).

>text -- if all you want is new text for contents of an element, or even
>a simple yes/no true/false type response.

>There's also XML, but then you need to deal with that in your script,
>and unless there's other consumers of your AJAX interface, I'd go with
>JSON instead.
>
>>[...]
>>     I thought it should be easy to find some basic code for this, but
>>no such luck.
>
>http://google.com/search?hl=en&q=php%20mysql%20ajax%20tutorial

     I have been looking and not finding.  Specific URLs would help.

>Those are for PHP, and for MySQL, but the essence is the same in
>whichever server-side scripting language.

     The essence for me is that I do not know how to make it work with
any language.  I need a start.

>>[...]
>>     The above use case implies changing the data and updating the row
>>and naturally, I want to be able to do more.  Being able to do the
>>above would be a good start.  My opposite number is unlikely to allow
>>adding additional software (Node.js, for example) on the server.
>
>So, what is your server, and what is available to run on it without
>upsetting your opposite number? e.g. Linux/Unix vs Windows, Classic ASP
>and .NET vs PHP, Ruby, Python... these things change your approach, so
>tell us more.

     I could use Classic ASP.  I do not know if I can use anything
else.  My opposite number knows even less about this than I do.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#15051

FromRoss McKay <au.org.zeta.at.rosko@invalid.invalid>
Date2012-07-14 21:40 +1000
Message-ID<69b208ln2qvvjerv1jvqnkebsb0f8p955n@4ax.com>
In reply to#15049
On Fri, 13 Jul 2012 21:18:41 -0700, Gene Wirchenko wrote:

>     I would like to fill a form with the values.  I would need each
>column name and value.  The values might need some escaping; if so,
>what?  The values might need some formatting; I can handle that.

Let's take JSON as "the way", because it will give you most flexibility
with least headache. Any escaping necessary should be handled by your
server-side script[1] solely to provide you with clean JSON; your
client-side script should not need escaping unless you are generating
HTML, which you probably don't need to do. You have the option of
formatting your values server-side (pre-encoding) or client-side.

With a JSON object encapsulating the data as, say, an object with
property names matching field names, and their values being the values
to populate the fields with, you can then iterate over the properties of
the object to populate the fields like this:

var frm = document.getElementById("my-form");
var response = /* what you get back from your AJAX request */;
var i;

for (i in response) {
	if (i in frm.elements) {
		frm.elements[i].value = response[i];
	}
}

[1] e.g. in PHP, you use json_encode() to get a string containing a JSON
representation of your data; see link. 
http://au2.php.net/manual/en/function.json-encode.php

For Classic ASP, I hacked together a solution for a client once, and it
seems to work OK; see link. NB: the client prefers code in VBScript,
which I tried to stick to, but JScript does some things better; so this
creature is a combination of both :(
https://github.com/webaware/ASP-JSONEncode

>     ANy of the suggestions below might work for me, but I do not know
>how to get any of them to work.  Basic URLs would help.  If I can get
>a basic case going, I will probably be off to the races.  Currently, I
>am spinning.

So, either my Google juice is too depleted after a hard week, or it's
hard to find a simple example of this. So I made one:

https://gist.github.com/3110728

It's very simplistic, but it has:

* SQL
* a simple AJAX service (in PHP)
* a simple AJAX client
* a form filled from AJAX

When you type in an ID of "123", it will pull the other fields from the
database.

I kept it as simple as I could, using basic JavaScript in a standards-
compliant browser and bugger all server-side code. You'd need to throw
some structure around it and more error handling, but I'm sure you're up
to that :)

>     I could use Classic ASP.  I do not know if I can use anything
>else.  My opposite number knows even less about this than I do.

USENET will be all too happy to tell you too many options if you ask us.
Go on! But you can narrow down your options by telling us what your
server infrastructure is, e.g. OS, web server, database server.

I generally would discourage Classic ASP for new work, but lots of it
happens every day anyway. Having just done some maintenance work on an
aging Classic ASP site, I'm glad it at least supports JScript in
server-side code because VBScript can be a right PITA.

PHP is an easy one to pick up, and then clean up afterwards, and is at
least still evolving. It's a really poorly put together language, and a
huge chunk of the web runs on it very successfully.

ASP.NET could be a better choice if you're a Windows shop. And if you're
into that sort of thing.
-- 
Ross McKay, Toronto, NSW Australia
"Before enlightenment: chop wood, carry water;
 After enlightenment: chop wood, carry water" - Wu Li

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web