[MonetDB-users] Name of fields in query result?
Hello. Here are a few functions/methods from the postgresql-ocaml binding.
class type result = object (** Main routines *)
method nfields : int (** [#nfields] @return the number of fields in a query result. *)
method fname : int -> string (** [#fname n] @return the name of the [n]th field.
@raise Error if field out of range. *)
method fnumber : string -> int (** [#fnumber field] @return the index of the field named [field].
@raise Not_found if no such named field. *)
I'm looking for equivalents of fname and fnumber methods in MAPI. Couldn't find an equivalent. So, is there a way, when you get the result of a query, to get the names of the fields in the result? All the best, -- Guillaume Yziquel http://yziquel.homelinux.org/
On 02-03-2010 00:58:56 +0100, Guillaume Yziquel wrote:
Hello.
Here are a few functions/methods from the postgresql-ocaml binding.
class type result = object (** Main routines *)
method nfields : int (** [#nfields] @return the number of fields in a query result. *)
method fname : int -> string (** [#fname n] @return the name of the [n]th field.
@raise Error if field out of range. *)
method fnumber : string -> int (** [#fnumber field] @return the index of the field named [field].
@raise Not_found if no such named field. *)
I'm looking for equivalents of fname and fnumber methods in MAPI. Couldn't find an equivalent. So, is there a way, when you get the result of a query, to get the names of the fields in the result?
Did you check mapi_get_field_count and mapi_get_table, mapi_get_name, mapi_get_type and mapi_get_len? Ok, I admit they are actually not documented at all, not even in the code.
Fabian Groffen a écrit :
I'm looking for equivalents of fname and fnumber methods in MAPI. Couldn't find an equivalent. So, is there a way, when you get the result of a query, to get the names of the fields in the result?
Did you check mapi_get_field_count and mapi_get_table, mapi_get_name, mapi_get_type and mapi_get_len?
Ok, I admit they are actually not documented at all, not even in the code.
Yes. I discovered them late last night by looking at the php bindings. Page 225 of m5manual.pdf. For instance proto string monetdb_field_name proto string monetdb_field_table proto string monetdb_field_type and had a look in the monetdb-client-1.34.2/src/php/Cimpl/php_monetdb.c file: Line 1449:
/* {{{ proto string monetdb_field_name(resource result, int field_number) Returns the name of the field */ PHP_FUNCTION(monetdb_field_name) { php_monetdb_get_field_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP_MONETDB_FIELD_NAME); } /* }}} */
and line 1402:
/* {{{ php_monetdb_get_field_info */ static void php_monetdb_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type) {
[...]
switch (entry_type) { case PHP_MONETDB_FIELD_NAME: Z_STRVAL_P(return_value) = mapi_get_name(monetdb_result, Z_LVAL_PP(field)); Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value)); Z_STRVAL_P(return_value) = estrndup(Z_STRVAL_P(return_value),Z_STRLEN_P(return_value)); Z_TYPE_P(return_value) = IS_STRING; break; case PHP_MONETDB_FIELD_TABLE: Z_STRVAL_P(return_value) = mapi_get_table(monetdb_result, Z_LVAL_PP(field)); Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value)); Z_STRVAL_P(return_value) = estrndup(Z_STRVAL_P(return_value),Z_STRLEN_P(return_value)); Z_TYPE_P(return_value) = IS_STRING; break; case PHP_MONETDB_FIELD_TYPE: Z_STRVAL_P(return_value) = mapi_get_type(monetdb_result, Z_LVAL_PP(field)); Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value)); Z_STRVAL_P(return_value) = estrndup(Z_STRVAL_P(return_value),Z_STRLEN_P(return_value)); Z_TYPE_P(return_value) = IS_STRING; break; default: RETURN_FALSE; } } /* }}} */
So you can indeed find the mapi_get_name/table/type functions, but they are only documented through the PHP interface, not the regular Mapi documentation. Fixing that would be great, I guess. -- Guillaume Yziquel http://yziquel.homelinux.org/
Guillaume Yziquel a écrit :
Fabian Groffen a écrit :
I'm looking for equivalents of fname and fnumber methods in MAPI. Couldn't find an equivalent. So, is there a way, when you get the result of a query, to get the names of the fields in the result? Did you check mapi_get_field_count and mapi_get_table, mapi_get_name, mapi_get_type and mapi_get_len?
Ok, I admit they are actually not documented at all, not even in the code.
Yes. I discovered them late last night by looking at the php bindings. Page 225 of m5manual.pdf. For instance
The MAL statement 'io.print(1);' returns a table, with one column, but whose only field does not have a name. What should I choose a MAL statement to be, if I want a similar result, but with a named field? All the best, -- Guillaume Yziquel http://yziquel.homelinux.org/
On 02-03-2010 13:03:26 +0100, Guillaume Yziquel wrote:
Guillaume Yziquel a écrit :
Fabian Groffen a écrit :
I'm looking for equivalents of fname and fnumber methods in MAPI. Couldn't find an equivalent. So, is there a way, when you get the result of a query, to get the names of the fields in the result? Did you check mapi_get_field_count and mapi_get_table, mapi_get_name, mapi_get_type and mapi_get_len?
Ok, I admit they are actually not documented at all, not even in the code.
Yes. I discovered them late last night by looking at the php bindings. Page 225 of m5manual.pdf. For instance
The MAL statement 'io.print(1);' returns a table, with one column, but whose only field does not have a name.
What should I choose a MAL statement to be, if I want a similar result, but with a named field?
SQL: select 1; Using MAL you cannot expect to get resultsets, like SQL does. Hence, I'd say: don't use it.
Fabian Groffen a écrit :
On 02-03-2010 13:03:26 +0100, Guillaume Yziquel wrote:
Guillaume Yziquel a écrit :
Yes. I discovered them late last night by looking at the php bindings. Page 225 of m5manual.pdf. For instance
The MAL statement 'io.print(1);' returns a table, with one column, but whose only field does not have a name.
What should I choose a MAL statement to be, if I want a similar result, but with a named field?
SQL: select 1;
Thanks.
Using MAL you cannot expect to get resultsets, like SQL does. Hence, I'd say: don't use it.
I'm not using MAL for the pure pleasure of using it. Nevertheless, there's something I do not understand: isn't SQL compiled to MAL? Then how come you could have resultsets in SQL and not in MAL? All the best, -- Guillaume Yziquel http://yziquel.homelinux.org/
On 2010-03-02 13:22, Guillaume Yziquel wrote:
Fabian Groffen a écrit :
On 02-03-2010 13:03:26 +0100, Guillaume Yziquel wrote:
Guillaume Yziquel a écrit :
Yes. I discovered them late last night by looking at the php bindings. Page 225 of m5manual.pdf. For instance
The MAL statement 'io.print(1);' returns a table, with one column, but whose only field does not have a name.
What should I choose a MAL statement to be, if I want a similar result, but with a named field?
SQL: select 1;
Thanks.
Using MAL you cannot expect to get resultsets, like SQL does. Hence, I'd say: don't use it.
I'm not using MAL for the pure pleasure of using it.
Nevertheless, there's something I do not understand: isn't SQL compiled to MAL? Then how come you could have resultsets in SQL and not in MAL?
All the best,
It you try explain select 1; you'll see that what it does is call the MAL function sql.exportValue(). The implementation of this function creates the resultset. -- Sjoerd Mullender
Sjoerd Mullender a écrit :
It you try explain select 1; you'll see that what it does is call the MAL function sql.exportValue(). The implementation of this function creates the resultset.
Thank you so much:
yziquel@seldon:~$ merovingian yziquel@seldon:~$ monetdb create test created database in maintenance mode: test yziquel@seldon:~$ monetdb status name state uptime health last crash test locked yziquel@seldon:~$ monetdb start test starting database 'test'... done yziquel@seldon:~$ monetdb status test name state uptime health last crash test locked 20s 100%, 0s - yziquel@seldon:~$ mclient --database=test --user=monetdb --passwd=monetdb -lsql Welcome to mclient, the MonetDB/SQL interactive terminal Database: MonetDB v5.18.1, 'test' Type \q to quit, \? for a list of available commands auto commit mode: on sql>explain select 1; +----------------------------------------------------------------------------------------+ | mal | +========================================================================================+ | function user.s1_1{autoCommit=true}():void; | | sql.exportValue(1,".","single_value","tinyint",8,0,6,1,""); | | end s1_1; | +----------------------------------------------------------------------------------------+ 3 tuples sql>
-- Guillaume Yziquel http://yziquel.homelinux.org/
On 02/03/10 13:22, Guillaume Yziquel wrote:
Fabian Groffen a écrit :
On 02-03-2010 13:03:26 +0100, Guillaume Yziquel wrote:
Guillaume Yziquel a écrit :
Yes. I discovered them late last night by looking at the php bindings. Page 225 of m5manual.pdf. For instance
The MAL statement 'io.print(1);' returns a table, with one column, but whose only field does not have a name.
What should I choose a MAL statement to be, if I want a similar result, but with a named field?
The SQL format depends on the SQL catalog and functions to implement the SQL result set for the Mapi protocol. The latter you did not wanted to use in the first place.
regards, Martin
SQL: select 1;
Thanks.
Using MAL you cannot expect to get resultsets, like SQL does. Hence, I'd say: don't use it.
I'm not using MAL for the pure pleasure of using it.
Nevertheless, there's something I do not understand: isn't SQL compiled to MAL? Then how come you could have resultsets in SQL and not in MAL?
All the best,
participants (4)
-
Fabian Groffen
-
Guillaume Yziquel
-
Martin Kersten
-
Sjoerd Mullender