Re: [webdatabase] Handling of the query arguments

2009-12-01 Thread Ian Hickson
On Thu, 19 Nov 2009, Maciej Stachowiak wrote:
 
 ECMAScript defines a ToPrimitive conversion (Section 9.1 of ECMA-262 5th 
 edition). I think the right thing to do would be for some spec to point 
 to those steps. Probably it has to be Web Database, because in many 
 cases where a Web IDL method takes an any type, it's not appropriate 
 to do ToPrimitive conversion.

So required.

-- 
Ian Hickson   U+1047E)\._.,--,'``.fL
http://ln.hixie.ch/   U+263A/,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'



[webdatabase] Handling of the query arguments

2009-11-19 Thread João Eiras


Hi everyone.

Neither the web database specification, nor the IDL, specify the fine  
grained handling that implementation must do of the several possible  
values that can be passed in the 2nd argument to executeSql, considering  
that those ecmascript values need to be handled by the SQL engine, and  
therefore converted into a database compatible value.


The only reference to the arguments is the paragraph that tell that the  
arguments should be replaced, but I've already asked that paragraph  
language to be reviewed in

http://lists.w3.org/Archives/Public/public-webapps/2009JulSep/1329.html

Handling of ecmascript to database types could be done the following way:
 - numerical values would be converted to REAL
 - strings would be converted to TEXT, including the empty string
 - booleans would be converted to lowercase TEXT false or true
 - null and undefined would be handled as NULL
 - functions would be converted to TEXT

Objects, which do not fit the primitive types about, can be handled in two  
ways.


1) The quick cheap way, which was already hinted, would be to convert them  
to string.
However, that's not very helpful, if the object is a native type wrapper  
like:

 new String(aa);
 new Number(1);
 new Boolean(true)

2) We can define, in the Web IDL, how an object can be converted to a  
primitive type.
Specifically, in an ecmascript binding we can do the following (note:  
returns means to stop the steps):

 - if object is null, return null
 - if object has a member function called valueOf, invoke valueOf in the  
context of object

   - if the returned value is a primitive type, return the value,
 - if object has a member function called toString, invoke toString in the  
context of object

   - if the returned value is a primitive type, return the value,
 - return Object.prototype.toString.call(object), so we get [object  
Class]


The returned primitive type would then go through the ecmascript to  
database type steps above.


However, the Web IDL need to be language agnostic, so I'll leave for the  
Web IDL maintainers to decide if this is of its scope and specifiable.


There might need to be clarification on how to define what is a numerical  
value, a string, a boolean, null and undefined, and functions.
We could say that a numerical value is just a number, but ideally, it  
should also include Number() instances, despite these could return non  
numerical values from their valueOf, but then we would go into the  
object-to-primitive steps.


The complete, we need the specification to tell how to convert database  
types back into ecmascript object, but this is easier:

 - TEXT, and other text types are converted to DOMString
 - REAL and other number types are converted to double
 - NULL is converted to null
 - DATE/TIMESTAMP types should be converted to Date objects, if supported

Thank you for your time.

--

João Eiras
Core Developer, Opera Software ASA, http://www.opera.com/



Re: [webdatabase] Handling of the query arguments

2009-11-19 Thread Maciej Stachowiak


On Nov 19, 2009, at 2:12 PM, João Eiras wrote:



Hi everyone.

Neither the web database specification, nor the IDL, specify the  
fine grained handling that implementation must do of the several  
possible values that can be passed in the 2nd argument to  
executeSql, considering that those ecmascript values need to be  
handled by the SQL engine, and therefore converted into a database  
compatible value.


The only reference to the arguments is the paragraph that tell that  
the arguments should be replaced, but I've already asked that  
paragraph language to be reviewed in
http://lists.w3.org/Archives/Public/public-webapps/2009JulSep/ 
1329.html


Handling of ecmascript to database types could be done the following  
way:

- numerical values would be converted to REAL
- strings would be converted to TEXT, including the empty string
- booleans would be converted to lowercase TEXT false or true
- null and undefined would be handled as NULL
- functions would be converted to TEXT

Objects, which do not fit the primitive types about, can be handled  
in two ways.


1) The quick cheap way, which was already hinted, would be to  
convert them to string.
However, that's not very helpful, if the object is a native type  
wrapper like:

new String(aa);
new Number(1);
new Boolean(true)

2) We can define, in the Web IDL, how an object can be converted to  
a primitive type.
Specifically, in an ecmascript binding we can do the following  
(note: returns means to stop the steps):

- if object is null, return null
- if object has a member function called valueOf, invoke valueOf in  
the context of object

  - if the returned value is a primitive type, return the value,
- if object has a member function called toString, invoke toString  
in the context of object

  - if the returned value is a primitive type, return the value,
- return Object.prototype.toString.call(object), so we get [object  
Class]


ECMAScript defines a ToPrimitive conversion (Section 9.1 of ECMA-262  
5th edition). I think the right thing to do would be for some spec to  
point to those steps. Probably it has to be Web Database, because in  
many cases where a Web IDL method takes an any type, it's not  
appropriate to do ToPrimitive conversion.


Regards,
Maciej




Re: [webdatabase] Handling of the query arguments

2009-11-19 Thread João Eiras


2) We can define, in the Web IDL, how an object can be converted to a  
primitive type.
Specifically, in an ecmascript binding we can do the following (note:  
returns means to stop the steps):

- if object is null, return null
- if object has a member function called valueOf, invoke valueOf in the  
context of object

  - if the returned value is a primitive type, return the value,
- if object has a member function called toString, invoke toString in  
the context of object

  - if the returned value is a primitive type, return the value,
- return Object.prototype.toString.call(object), so we get [object  
Class]


ECMAScript defines a ToPrimitive conversion (Section 9.1 of ECMA-262 5th  
edition). I think the right thing to do would be for some spec to point  
to those steps. Probably it has to be Web Database, because in many  
cases where a Web IDL method takes an any type, it's not appropriate  
to do ToPrimitive conversion.




Indeed !

--

João Eiras
Core Developer, Opera Software ASA, http://www.opera.com/