SSQLBuilder Class Reference

#include <storage/GenericIterable.h>

Inheritance diagram for SSQLBuilder:

BGenericIterable BGenericIterable::GenericIterator BCatalogDelegate BIndexedIterable BSchemaRowIDJoin BSchemaTableNode BCatalogDelegate::IteratorDelegate BIndexedIterable::IndexedIterator BSchemaRowIDJoin::JoinIterator BSchemaTableNode::QueryIterator List of all members.

Detailed Description

Convenience class for converting SValue queries in to SQL queries.


SQL APIs

Convenience functions for building SQL strings, and virtuals you can override to extend or modify its behavior.

status_t BuildSQLString (SString *outSql, SValue *inoutArgs, const SString &dbname) const
 Convert an SValue query to a SQL query.
status_t BuildSQLSubStrings (SString *outSelect, SString *outWhere, SString *outOrderBy, SValue *inoutArgs) const
 Lower-level version of BuildSQLQuery, to extract individual strings.
virtual SValue CreateSQLFilter (const SValue &filter) const
 Override to convert a BV_ITERABLE_FILTER into the corresponding WHERE construct.
virtual void MapSQLColumn (SValue *inoutColumn) const
 Override to map column names in the query arguments to other column(s) in the SQL string.
virtual void MapSQLOrderColumn (SValue *inoutColumnName, SValue *inoutOrder) const
 Override to map column names in the "order by" argument to other column(s) in the SQL string.

Bookkeeping

Creation, destruction, etc.

 SSQLBuilder ()
virtual ~SSQLBuilder ()


Constructor & Destructor Documentation

SSQLBuilder  ) 
 

~SSQLBuilder  )  [virtual]
 


Member Function Documentation

status_t BuildSQLString SString outSql,
SValue inoutArgs,
const SString dbname
const
 

Convert an SValue query to a SQL query.

Takes an SValue query (containing the mappings BV_ITERABLE_SELECT, BV_ITERABLE_FILTER, BV_ITERABLE_WHERE, and BV_ITERABLE_ORDER_BY) and generates the corresponding SQL query string.

Parameters:
[out] outSql The resulting SQL string to be handed off to the database.
[in,out] inoutArgs Incoming, this is the iterator's arguments as provider to ParseArgs(). Outgoing, it is the actual arguments used in constructing the SQL string to be returned by Options().
[in] dbname Database name to be used in SQL string.
Returns:
B_OK if all is well, else an error code.

status_t BuildSQLSubStrings SString outSelect,
SString outWhere,
SString outOrderBy,
SValue inoutArgs
const
 

Lower-level version of BuildSQLQuery, to extract individual strings.

SValue CreateSQLFilter const SValue filter  )  const [virtual]
 

Override to convert a BV_ITERABLE_FILTER into the corresponding WHERE construct.

The default implementation simply returns B_UNDEFINED_VALUE, meaning the filters are not supported. You should override to return a BV_ITERABLE_WHERE SValue mapping to perform the appropriate query for your iterator.

Reimplemented in BSchemaTableNode::QueryIterator, and BGenericIterable::GenericIterator.

void MapSQLColumn SValue inoutColumn  )  const [virtual]
 

Override to map column names in the query arguments to other column(s) in the SQL string.

The default implementation simply leaves inoutColumn as-is. You implement this to change the column name supplied by the client to a different column name to be used in the SQL query. If you change inoutColumn to B_NULL_VALUE, it will be silently ignored. If you change inoutColumn to an SValue containing a status code that error will be returned.

Todo:
Should support mappings from one SValue column to multiple SQL columns.

Reimplemented in BGenericIterable::GenericIterator.

void MapSQLOrderColumn SValue inoutColumnName,
SValue inoutOrder
const [virtual]
 

Override to map column names in the "order by" argument to other column(s) in the SQL string.

The input inoutColumnName is the column being sorted, and inoutOrder is how to sort (these correspond to {column_name->order} in BV_ITERABLE_ORDER_BY). The default implementation simply calls MapSQLColumn to change the name of inoutColumnName.

You can use this for fine-grained control of how ordering happens for a column. To map the input columns to multiple columns in the SQL query, change inoutColumnName to a complex mapping of the same form as BV_ITERABLE_ORDER_BY. In that case, inoutOrder will be ignored.

Like MapSQLColumn(), you can set inoutColumnName to B_NULL_VALUE or an error code to skip the column or return an error, respectively.

Reimplemented in BSchemaTableNode, and BGenericIterable::GenericIterator.


The documentation for this class was generated from the following files: