src/server/TableDef.cxx

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by www.databasecache.com                           *
00003  *   Contact: praba_tuty@databasecache.com                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
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   ***************************************************************************/
00016 #include<Table.h>
00017 #include<Index.h>
00018 #include<CatalogTables.h>
00019 #include<Lock.h>
00020 
00021 TableDef::~TableDef()
00022 {
00023     reset();
00024 }
00025 void TableDef::reset()
00026 {
00027     fldList.removeAll();
00028     fldCount = 0;
00029 }
00030 int TableDef::addField(const char *name,  DataType type, size_t length,
00031                  const void *defaultValue, bool notNull)
00032 {
00033     if (name == NULL) return (int)ErrBadArg;
00034     // The following code checks for duplicates
00035     FieldIterator iter = getFieldIterator();
00036     while (iter.hasElement())
00037     {
00038         FieldDef def = iter.nextElement();
00039         if (! strcmp(def.fldName_, name)) {
00040             printError(ErrAlready, "Field %s already Exists", name);
00041             return (int) ErrAlready;
00042         }
00043     }
00044     FieldDef fldDef;
00045     strcpy(fldDef.fldName_, name);
00046     fldDef.fldName_[IDENTIFIER_LENGTH] = '\0';
00047     fldDef.type_ = type;
00048     fldDef.length_ = length;
00049     if (defaultValue != NULL)
00050     {
00051         fldDef.isDefault_ = true;
00052         os::memcpy(fldDef.defaultValueBuf_, defaultValue,
00053                                 DEFAULT_VALUE_BUF_LENGTH);
00054     }
00055     else
00056     {
00057         fldDef.isDefault_ = false;
00058         os::memset(fldDef.defaultValueBuf_,0, DEFAULT_VALUE_BUF_LENGTH);
00059     }
00060     fldDef.isNull_ = notNull;
00061     switch(type)
00062     {
00063         case typeString :
00064         case typeBinary:
00065             fldDef.length_ = length;
00066             break;
00067         default:
00068             fldDef.length_ = AllDataType::size(type);
00069             break;
00070     }
00071     int ret = fldList.append(fldDef);
00072     if (0 == ret)  fldCount++;
00073     return ret;
00074 }
00075 
00076 int TableDef::dropField(const char *name)
00077 {
00078     int ret = fldList.remove(name);
00079     if (0 == ret) fldCount--;
00080     return ret;
00081 }
00082 
00083 int TableDef::getFieldCount()
00084 {
00085     return fldCount;
00086 }
00087 
00088 size_t TableDef::getTupleSize()
00089 {
00090     size_t length = 0;
00091     FieldIterator iter = getFieldIterator();
00092     while (iter.hasElement())
00093     {
00094         FieldDef def = iter.nextElement();
00095         length = length + os::align(def.length_);
00096     }
00097     return length;
00098 }

Generated on Mon Jun 9 22:37:15 2008 for csql by  doxygen 1.4.7