From: Sean Kinsey on
On Apr 14, 10:33 am, "Evertjan." <exjxw.hannivo...(a)interxnl.net>
wrote:
> Jeff North wrote on 14 apr 2010 in comp.lang.javascript:
>
>
>
>
>
> > On 13 Apr 2010 19:09:01 GMT, in comp.lang.javascript Rob Christiansen
> > <robb_christian...(a)q.com>
> > <4bc4c14d$0$89865$815e3...(a)news.qwest.net> wrote:
>
> >>|
> >>| My 1st *.mdb file works great, My 2nd doesn't.  I get a lot of "data
> >>| type mismatch" error messages. The problem as i see it is, whereas
> >>| all the fields in the 1st file are 'text,' the 2nd is 'text,'
> >>| 'date/time,' and 'currency.' The software is apparently having
> >>| trouble reading the different types. Below is the sql statement I'm
> >>| using. How can i fix this?
> >>| -------------------------------------
> >>| fdate   is set as "date/time" type
> >>| fdebit  is set as "currency" type
> >>| fcredit is set as "currency" type
> >>| fprevrec and fnextrec are number type
> >>| newid is set as "auto" type
> >>| all the rest are "text" type
> >>|
> >>| SQL = "INSERT INTO books1 VALUES( "+ newid +", "+ fprevrec +", "+
> >>| fnextrec +", '"+ fforegrnd +"', '"+ fbackgrnd +"', '"+ fyear+"', '"+
> >>| fmonth  +"', '"+ fbank+"', '"+ finitials +"', '"+ ftype+"', '"+
> >>| fcheck+"', '"+ fdate+"', '"+ fdescription+"', "+ fdebit+", "+
> >>| fcredit+", '"+ fproject+"', '"+ fmsc1 +"', '"+ fmsc2 +"', '"+ fmsc3
> >>| +"', '"+ fmsc4 +"', '"+ fmsc5 +"', '"+ fmsc6 +"' )";  //, '"+ fmsc7
> >>| +"' '"+ fmsc8 +"' )";  //
> >>|
> >>| crazyswede
>
> > 1. This is a javascript newsgroup and nothing to do with sql syntax
>
> I do not agree.
>
> The above code is written in Javascript.
>
> ASP-javascript can be a valuable tool for preparing
> and executing sql strings.
>
> See my other posting, with functions like ths one:
>
> function setSQLstr(theVar) {
>    if (SQL!='') SQL += ',';
>    SQL += "'" + theVar + "'";
>
> };
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

If you insist on using such a helper function with JScript, it should
be more like this

var pairs={};
function addString(col, val){
pairs[col] = "'" + val + "'";
}


var cols=[], vals=[], sql;
//if insert
for (var col in pairs) if pairs.hasOwnKey(col) {
cols.push(col);
vals.push(pair[col]);
}
sql = "INSERT INTO [table](" + cols.join(",") + ") VALUES (" +
vals.join(",") + ")";


//if update
for (var col in pairs) if pairs.hasOwnKey(col) {
vols.push(col + "=" + pairs[col];
}
sql = "UPDATE [table] SET " + cols.join(",") + " WHERE foo=bar";

maybe even some proper escaping could be added :)
From: Evertjan. on
Sean Kinsey wrote on 14 apr 2010 in comp.lang.javascript:

>> See my other posting, with functions like ths one:
>>
>> function setSQLstr(theVar) {
>> � �if (SQL!='') SQL += ',';
>> � �SQL += "'" + theVar + "'";
>>
>> };

[please do not quote signatures on usenet]


> If you insist on using such a helper function with JScript, it should
> be more like this

A bit strange answering on the content
of part of another posting in this thread,

and no I do not insist, why should I, I just give a helpful advice

>
> var pairs={};
> function addString(col, val){
> pairs[col] = "'" + val + "'";
>}

So if you want to compair with my script, that is much nmore versatile and
readable btw, please do so by responding to that posting.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
From: Jeff North on
On 14 Apr 2010 08:33:50 GMT, in comp.lang.javascript "Evertjan."
<exjxw.hannivoort(a)interxnl.net>
<Xns9D5A6B78E98D5eejj99(a)194.109.133.242> wrote:

>| Jeff North wrote on 14 apr 2010 in comp.lang.javascript:
>|
>| > On 13 Apr 2010 19:09:01 GMT, in comp.lang.javascript Rob Christiansen
>| > <robb_christiansen(a)q.com>
>| > <4bc4c14d$0$89865$815e3792(a)news.qwest.net> wrote:
>| >
>| >>|
>| >>| My 1st *.mdb file works great, My 2nd doesn't. I get a lot of "data
>| >>| type mismatch" error messages. The problem as i see it is, whereas
>| >>| all the fields in the 1st file are 'text,' the 2nd is 'text,'
>| >>| 'date/time,' and 'currency.' The software is apparently having
>| >>| trouble reading the different types. Below is the sql statement I'm
>| >>| using. How can i fix this?
>| >>| -------------------------------------
>| >>| fdate is set as "date/time" type
>| >>| fdebit is set as "currency" type
>| >>| fcredit is set as "currency" type
>| >>| fprevrec and fnextrec are number type
>| >>| newid is set as "auto" type
>| >>| all the rest are "text" type
>| >>|
>| >>| SQL = "INSERT INTO books1 VALUES( "+ newid +", "+ fprevrec +", "+
>| >>| fnextrec +", '"+ fforegrnd +"', '"+ fbackgrnd +"', '"+ fyear+"', '"+
>| >>| fmonth +"', '"+ fbank+"', '"+ finitials +"', '"+ ftype+"', '"+
>| >>| fcheck+"', '"+ fdate+"', '"+ fdescription+"', "+ fdebit+", "+
>| >>| fcredit+", '"+ fproject+"', '"+ fmsc1 +"', '"+ fmsc2 +"', '"+ fmsc3
>| >>| +"', '"+ fmsc4 +"', '"+ fmsc5 +"', '"+ fmsc6 +"' )"; //, '"+ fmsc7
>| >>| +"' '"+ fmsc8 +"' )"; //
>| >>|
>| >>| crazyswede
>| >
>| > 1. This is a javascript newsgroup and nothing to do with sql syntax
>|
>| I do not agree.
>|
>| The above code is written in Javascript.

It was more likely written in server-side JScript.

>| ASP-javascript can be a valuable tool for preparing
>| and executing sql strings.
>|
>| See my other posting, with functions like ths one:
>|
>| function setSQLstr(theVar) {
>| if (SQL!='') SQL += ',';
>| SQL += "'" + theVar + "'";
>| };
>|

Are you condoning people write their database update statements in
client-side JavaScript?
From: Sean Kinsey on
On Apr 14, 4:16 pm, "Evertjan." <exjxw.hannivo...(a)interxnl.net> wrote:
<snip>
> [please do not quote signatures on usenet]

Sorry, it slipped my mind.

>
> > If you insist on using such a helper function with JScript, it should
> > be more like this
>
> A bit strange answering on the content
> of part of another posting in this thread,

Not in this newsgroup :)

<snip>
> So if you want to compair with my script, that is much nmore versatile and
> readable btw, please do so by responding to that posting.

I cannot really say if either one is more versatile or readable; but I
do know that not specifying columns names, and just _hoping_ that the
order you call setSQLstr(foo) with is forever the same as the order of
the columns in the database is asking for trouble.
And why bother with all that string concatenation.

Actually, I will say that my code is more versatile as it supports
both INSERT and UPDATE without duplicating 90% of the code, and you
know what; I'm actually favoring my code with regards to readability
as well.
What do you know..



From: Evertjan. on
Jeff North wrote on 14 apr 2010 in comp.lang.javascript:

>>| The above code is written in Javascript.
>
> It was more likely written in server-side JScript.

Whish is Just Javascript smelling less sweet.


>>| ASP-javascript can be a valuable tool for preparing
>>| and executing sql strings.
>>|
>>| See my other posting, with functions like ths one:
>>|
>>| function setSQLstr(theVar) {
>>| if (SQL!='') SQL += ',';
>>| SQL += "'" + theVar + "'";
>>| };
>
> Are you condoning people write their database update statements in
> client-side JavaScript?

I am not condoning the use of the word condoning by you.

For the rest I am not in the habit
of condoning or not condoning anyone to do anything.

Why the heck would you think the above is clientside?

Do you by chance mistakingly think
that this NG is only about clientside Javascript?

Javascript as a serverside language is a very usefull language.

You even can duplicate the same functions serverside and clientside, if
they do not use the server platform [ASP] or the client DOM. Very nice in
double validation of entries.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)