/** * (non-PHPdoc). * * @see Alpha\Model\ActiveRecordProviderInterface::checkRecordExists() */ public function checkRecordExists($OID) { self::$logger->debug('>>checkRecordExists(OID=[' . $OID . '])'); $sqlQuery = 'SELECT OID FROM ' . $this->BO->getTableName() . ' WHERE OID = ?;'; $this->BO->setLastQuery($sqlQuery); $stmt = self::getConnection()->stmt_init(); if ($stmt->prepare($sqlQuery)) { $stmt->bind_param('i', $OID); $stmt->execute(); $result = $this->bindResult($stmt); $stmt->close(); if ($result) { if (count($result) > 0) { self::$logger->debug('<<checkRecordExists [true]'); return true; } else { self::$logger->debug('<<checkRecordExists [false]'); return false; } } else { throw new AlphaException('Failed to check for the record [' . $OID . '] on the class [' . get_class($this->BO) . '] from the table [' . $this->BO->getTableName() . '], query is [' . $this->BO->getLastQuery() . ']'); self::$logger->debug('<<checkRecordExists [false]'); return false; } } else { throw new AlphaException('Failed to check for the record [' . $OID . '] on the class [' . get_class($this->BO) . '] from the table [' . $this->BO->getTableName() . '], query is [' . $this->BO->getLastQuery() . ']'); self::$logger->debug('<<checkRecordExists [false]'); return false; } }
/** * (non-PHPdoc). * * @see Alpha\Model\ActiveRecordProviderInterface::isTableOverloaded() */ public function isTableOverloaded() { self::$logger->debug('>>isTableOverloaded()'); $reflection = new ReflectionClass($this->BO); $classname = $reflection->getShortName(); $tablename = ucfirst($this->BO->getTableName()); // use reflection to check to see if we are dealing with a persistent type (e.g. DEnum) which are never overloaded $implementedInterfaces = $reflection->getInterfaces(); foreach ($implementedInterfaces as $interface) { if ($interface->name == 'Alpha\\Model\\Type\\TypeInterface') { self::$logger->debug('<<isTableOverloaded [false]'); return false; } } if ($classname != $tablename) { // loop over all BOs to see if there is one using the same table as this BO $BOclasses = ActiveRecord::getBOClassNames(); foreach ($BOclasses as $BOclassName) { $reflection = new ReflectionClass($BOclassName); $classname = $reflection->getShortName(); if ($tablename == $classname) { self::$logger->debug('<<isTableOverloaded [true]'); return true; } } throw new BadTableNameException('The table name [' . $tablename . '] for the class [' . $classname . '] is invalid as it does not match a BO definition in the system!'); self::$logger->debug('<<isTableOverloaded [false]'); return false; } else { // check to see if there is already a "classname" column in the database for this BO $sqlQuery = 'PRAGMA table_info(' . $this->BO->getTableName() . ')'; $result = self::getConnection()->query($sqlQuery); $this->BO->setLastQuery($sqlQuery); if (!$result) { self::$logger->warn('Error during pragma table info lookup [' . self::getLastDatabaseError() . ']'); } else { while ($row = $result->fetchArray(SQLITE3_ASSOC)) { if ('classname' == $row['name']) { self::$logger->debug('<<isTableOverloaded [true]'); return true; } } } self::$logger->debug('<<isTableOverloaded [false]'); return false; } }