NAME
DBIx::MyParse::Item - Accessing the items from a DBIx::MyParse
parse tree
SYNOPSIS
use DBIx::MyParse;
use DBIx::MyParse::Query;
use DBIx::MyParse::Item;
my $parser = DBIx::MyParse->new();
my $query = $parser->parse("SELECT field_name FROM table_name");
my $item_list = $query->getSelectItems();
my $first_item = $item_list->[0];
print $first_item->getType(); # Prints "FIELD_ITEM"
print $first_item->getFieldName() # Prints "field_name"
DESCRIPTION
MySQL uses a few dozen Item objects to store the various nodes possible in a parse tree. For the sake of simplicity, we only use a single object interface in Perl to access things.
METHODS
- my $item_type = $item->getType();
-
This returns the type of the Item as a string, to facilitate dumping and debugging.
if ($item_type eq 'FIELD_ITEM') { ... } # Correct if ($item_type == FIELD_ITEM) { ... } # Will not work
The possible values are listed in enum Type in sql/item.h in the MySQL source.
enum Type {FIELD_ITEM, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM, INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM, COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM, PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM, FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM, SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER, PARAM_ITEM };
From those, the following are explicitly supported:
FIELD_ITEM, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM, INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM REF_ITEM, COND_ITEM
In addition, DBIx::MyParse defines its own TABLE_ITEM in case a table, rather than a field, is being referenced.
REF_ITEM is a FIELD_ITEM that is used in a HAVING clause. VARBIN_ITEM is created when a Hex value is passed to MySQL (e.g. 0x5061756c).
- my $func_type = $item->getFuncType();
-
if $item->getType() eq "FUNC_ITEM", you can call getFuncType() to determine what type of function it is. For MySQL, all operators are also of type FUNC_ITEM.
The possible values are again strings (see above) and are listed in sql/item_func.h under enum Functype
enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC, GE_FUNC,GT_FUNC,FT_FUNC, LIKE_FUNC,NOTLIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC, COND_AND_FUNC, COND_OR_FUNC, COND_XOR_FUNC, BETWEEN, IN_FUNC, INTERVAL_FUNC, ISNOTNULLTEST_FUNC, SP_EQUALS_FUNC, SP_DISJOINT_FUNC,SP_INTERSECTS_FUNC, SP_TOUCHES_FUNC,SP_CROSSES_FUNC,SP_WITHIN_FUNC, SP_CONTAINS_FUNC,SP_OVERLAPS_FUNC, SP_STARTPOINT,SP_ENDPOINT,SP_EXTERIORRING, SP_POINTN,SP_GEOMETRYN,SP_INTERIORRINGN, NOT_FUNC, NOT_ALL_FUNC, NOW_FUNC, VAR_VALUE_FUNC };
if $item->getType() eq "SUM_FUNC_ITEM", $item->getFuncType() can be any of the aggregate functions listed in enum Sumfunctype in sql/item_sum.h:
enum Sumfunctype { COUNT_FUNC,COUNT_DISTINCT_FUNC,SUM_FUNC,AVG_FUNC,MIN_FUNC, MAX_FUNC, UNIQUE_USERS_FUNC,STD_FUNC,VARIANCE_FUNC,SUM_BIT_FUNC, UDF_SUM_FUNC, GROUP_CONCAT_FUNC };
For MySQL, all functions not specifically listed above are UNKNOWN_FUNC and you must call getFuncName().
- my $func_name = $item->getFuncName();
-
Returns the name of the function called, such as "concat_ws", "md5", etc. If $item is not a function, but an operator, the symbol of the operator is returned, such as "+", "||", etc. The name of the function will be lowercase regardless of the orginal case in the SQL string.
- my $arguments_ref = $item->getArguments();
-
Returns a reference to an array containing all the arguments to the function/operator. Each item from the array is also an DBIx::MyParse::Item object, even if it is a simple string or a field name.
- my $database_name = $item->getDatabaseName();
-
if $item is FIELD_ITEM, REF_ITEM or a TABLE_ITEM, getDatabaseName() returns the database the field belongs to, if it was explicitly specified. If it was not specified explicitly, such as was given previously with a "USE DATABASE" command, getDatabaseName() will return undef. This may change in the future if we incorporate some more of MySQL's logic
- my $table_name = $item->getTableName();
-
Returns the name of the table for a FIELD_ITEM or TABLE_ITEM object. For FIELD_ITEM, the table name must be explicitly specified with "table_name.field_name" notation. Otherwise returns undef and does not attempt to guess the name of the table.
- my $field_name = $item->getTableName();
-
Returns the name of the field for a FIELD_ITEM object.
- my $value = $item->getValue();
-
Returns, as string, the value of STRING_ITEM, INT_ITEM, REAL_ITEM and VARBIN_ITEM objects.
- my $direction = $item->getOrderDir(); =item my $direction = $item->getGroupDir();
-
For an FIELD_ITEM used in GROUP BY or ORDER BY, those two identical functions return either the string "ASC" or the string "DESC" depending on the group/ordering direction. Default is "ASC" and will be returned even if the query does not specify a direction.
- my $alias = $item->getAlias();
-
Returns the name of the Item if provided with an AS clause, such as SELECT field AS alias.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 175:
=over without closing =back