1/* 2 * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24#include "PartialRelation.h" 25#include "TableRelation.h" 26#include "CommonCode.h" 27 28 29PartialRelation::PartialRelation (CSSM_DB_RECORDTYPE recordType, int numberOfColumns, columnInfoLoader *theColumnInfo) : 30 Relation (recordType), mNumberOfColumns (numberOfColumns) 31{ 32 if (mNumberOfColumns == 0) { 33 mColumnInfo = NULL; 34 return; 35 } 36 37 mColumnInfo = new columnInfo[mNumberOfColumns]; 38 for (int i = 0; i < mNumberOfColumns; ++i) { 39 mColumnInfo[i].mColumnName = new StringValue (theColumnInfo[i].mColumnName); 40 mColumnInfo[i].mColumnID = theColumnInfo[i].mColumnID; 41 mColumnInfo[i].mColumnFormat = theColumnInfo[i].mColumnFormat; 42 } 43} 44 45 46 47PartialRelation::~PartialRelation () 48{ 49 if (mColumnInfo != NULL) { 50 for (int i = 0; i < mNumberOfColumns; ++i) 51 delete mColumnInfo[i].mColumnName; 52 delete mColumnInfo; 53 } 54} 55 56 57StringValue *PartialRelation::GetColumnName (int i) 58{ 59 return mColumnInfo[i].mColumnName; 60} 61 62 63int PartialRelation::GetNumberOfColumns () 64{ 65 return mNumberOfColumns; 66} 67 68 69 70uint32 PartialRelation::GetColumnIDs (int i) 71{ 72 return mColumnInfo[i].mColumnID; 73} 74 75 76 77int PartialRelation::GetColumnNumber (const char* columnName) 78{ 79 // look for a column name that matches this columnName. If not, throw an exception 80 for (int i = 0; i < mNumberOfColumns; ++i) { 81 const char *s = mColumnInfo[i].mColumnName->GetRawValue(); 82 if (strncmp(s, columnName, strlen(s)) == 0) 83 return i; 84 } 85 return -1; 86} 87 88 89 90int PartialRelation::GetColumnNumber (uint32 columnID) 91{ 92 for (int i = 0; i < mNumberOfColumns; ++i) { 93 if (mColumnInfo[i].mColumnID == columnID) 94 return i; 95 } 96 return -1; 97} 98 99 100 101