[webdatabase] Handling of the query arguments

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/

Received on Thursday, 19 November 2009 22:13:26 UTC