Drizzled Public API Documentation

stored_key.cc

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include <config.h>
00021 
00022 #include <drizzled/field/varstring.h>
00023 #include <drizzled/session.h>
00024 #include <drizzled/stored_key.h>
00025 
00026 namespace drizzled
00027 {
00028 
00029 StoredKey::StoredKey(Session *session,
00030                      Field *field_arg, 
00031                      unsigned char *ptr,
00032                      unsigned char *null, 
00033                      uint32_t length) :
00034   null_key(0), 
00035   null_ptr(null), 
00036   err(0)
00037   {
00038     if (field_arg->type() == DRIZZLE_TYPE_BLOB)
00039     {
00040       /*
00041         Key segments are always packed with a 2 byte length prefix.
00042         See mi_rkey for details.
00043       */
00044       to_field= new Field_varstring(ptr,
00045                                     length,
00046                                     2,
00047                                     null,
00048                                     1,
00049                                     field_arg->field_name,
00050                                     field_arg->charset());
00051       to_field->init(field_arg->getTable());
00052     }
00053     else
00054     {
00055       to_field= field_arg->new_key_field(session->mem_root, field_arg->getTable(),
00056                                          ptr, null, 1);
00057     }
00058 
00059     to_field->setWriteSet();
00060   }
00061 
00062 StoredKey::store_key_result StoredKey::copy()
00063 {
00064   store_key_result result;
00065   Session *session= to_field->getTable()->in_use;
00066   enum_check_fields saved_count_cuted_fields= session->count_cuted_fields;
00067   session->count_cuted_fields= CHECK_FIELD_IGNORE;
00068   result= copy_inner();
00069   session->count_cuted_fields= saved_count_cuted_fields;
00070 
00071   return result;
00072 }
00073 
00074 } /* namespace drizzled */