/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: * * Copyright (C) 2008 Sun Microsystems * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef DRIZZLED_ITEM_PARAM_H #define DRIZZLED_ITEM_PARAM_H /* Item represents one placeholder ('?') of prepared statement */ class Item_param :public Item { char cnvbuf[MAX_FIELD_WIDTH]; String cnvstr; Item *cnvitem; public: enum enum_item_param_state { NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE, STRING_VALUE, TIME_VALUE, LONG_DATA_VALUE, DECIMAL_VALUE } state; /* A buffer for string and long data values. Historically all allocated values returned from val_str() were treated as eligible to modification. I. e. in some cases Item_func_concat can append it's second argument to return value of the first one. Because of that we can't return the original buffer holding string data from val_str(), and have to have one buffer for data and another just pointing to the data. This is the latter one and it's returned from val_str(). Can not be declared inside the union as it's not a POD type. */ String str_value_ptr; my_decimal decimal_value; union { int64_t integer; double real; /* Character sets conversion info for string values. Character sets of client and connection defined at bind time are used for all conversions, even if one of them is later changed (i.e. between subsequent calls to mysql_stmt_execute). */ struct CONVERSION_INFO { const CHARSET_INFO *character_set_client; const CHARSET_INFO *character_set_of_placeholder; /* This points at character set of connection if conversion to it is required (i. e. if placeholder typecode is not BLOB). Otherwise it's equal to character_set_client (to simplify check in convert_str_value()). */ const CHARSET_INFO *final_character_set_of_str_value; } cs_info; DRIZZLE_TIME time; } value; /* Cached values for virtual methods to save us one switch. */ enum Item_result item_result_type; enum Type item_type; /* Used when this item is used in a temporary table. This is NOT placeholder metadata sent to client, as this value is assigned after sending metadata (in setup_one_conversion_function). For example in case of 'SELECT ?' you'll get DRIZZLE_TYPE_STRING both in result set and placeholders metadata, no matter what type you will supply for this placeholder in mysql_stmt_execute. */ enum enum_field_types param_type; /* Offset of placeholder inside statement text. Used to create no-placeholders version of this statement for the binary log. */ uint32_t pos_in_query; Item_param(uint32_t pos_in_query_arg); enum Item_result result_type () const { return item_result_type; } enum Type type() const { return item_type; } enum_field_types field_type() const { return param_type; } double val_real(); int64_t val_int(); my_decimal *val_decimal(my_decimal*); String *val_str(String*); bool get_time(DRIZZLE_TIME *tm); bool get_date(DRIZZLE_TIME *tm, uint32_t fuzzydate); int save_in_field(Field *field, bool no_conversions); void set_null(); void set_int(int64_t i, uint32_t max_length_arg); void set_double(double i); void set_decimal(char *str, ulong length); bool set_str(const char *str, ulong length); bool set_longdata(const char *str, ulong length); void set_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type type, uint32_t max_length_arg); bool set_from_user_var(Session *session, const user_var_entry *entry); void reset(); /* Assign placeholder value from bind data. Note, that 'len' has different semantics in embedded library (as we don't need to check that packet is not broken there). See sql_prepare.cc for details. */ void (*set_param_func)(Item_param *param, unsigned char **pos, ulong len); const String *query_val_str(String *str) const; bool convert_str_value(Session *session); /* If value for parameter was not set we treat it as non-const so noone will use parameters value in fix_fields still parameter is constant during execution. */ virtual table_map used_tables() const { return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; } virtual void print(String *str, enum_query_type query_type); bool is_null() { assert(state != NO_VALUE); return state == NULL_VALUE; } bool basic_const_item() const; /* This method is used to make a copy of a basic constant item when propagating constants in the optimizer. The reason to create a new item and not use the existing one is not precisely known (2005/04/16). Probably we are trying to preserve tree structure of items, in other words, avoid pointing at one item from two different nodes of the tree. Return a new basic constant item if parameter value is a basic constant, assert otherwise. This method is called only if basic_const_item returned true. */ Item *safe_charset_converter(const CHARSET_INFO * const tocs); Item *clone_item(); /* Implement by-value equality evaluation if parameter value is set and is a basic constant (integer, real or string). Otherwise return false. */ bool eq(const Item *item, bool binary_cmp) const; /** Item is a argument to a limit clause. */ bool limit_clause_param; }; #endif /* DRIZZLED_ITEM_PARAM_H */