Exemplo n.º 1
0
 function getDB()
 {
     $this->db = new ImpPDO('sqlite:' . $this->TempFile);
     $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     DBObject::$DB = $this->db;
     ImpSQLBuilder::$DB = $this->db;
 }
Exemplo n.º 2
0
 protected function __construct($ID = false)
 {
     assert(!empty($this->Properties));
     assert(!isset($this->_classOverrides));
     assert(!isset($this->RequiredFormFields));
     assert(!isset($this->FormFields));
     if (!empty($GLOBALS['DB'])) {
         DBObject::$DB = $GLOBALS['DB'];
     }
     if (!empty($ID)) {
         if (is_array($ID)) {
             $this->setProperties($ID);
             $this->_initialValues = $ID;
         } else {
             $ID = intval($ID);
             if (empty($ID)) {
                 throw new InvalidArgumentException(get_class($this) . " constructor called with empty id {$ID}");
             }
             $Q = self::$DB->query($this->_generateSelect($this->DBTable, $this->Properties, "ID={$ID}"));
             if (count($Q) < 1) {
                 throw new InvalidArgumentException(get_class($this) . " constructor called with ID {$ID} which is not in {$this->DBTable}");
             } else {
                 assert(count($Q) == 1);
                 $this->ID = $ID;
                 $this->setProperties($Q[0]);
                 $this->_initialValues = $Q[0];
             }
         }
     } else {
         foreach ($this->Properties as $Name => $def) {
             if (is_array($def)) {
                 assert(isset($def['type']));
                 $Type = $def['type'];
             } else {
                 $Type = $def;
             }
             if (is_array($def) and array_key_exists('default', $def)) {
                 $this->{$Name} = $def['default'];
             } else {
                 switch ($Type) {
                     case 'date':
                     case 'datetime':
                     case 'timestamp':
                     case 'integer':
                         $this->{$Name} = (int) 0;
                         break;
                     case 'double':
                     case 'currency':
                         $this->{$Name} = (double) 0;
                     case 'string':
                     case 'enum':
                         $this->{$Name} = '';
                         break;
                     case 'set':
                         $this->{$Name} = array();
                         break;
                     case 'collection':
                         break;
                     case 'object':
                         // TODO: this breaks __set(), presumably due to a recursive call: $this->$Name = null;
                         break;
                     case 'boolean':
                         $this->{$Name} = false;
                         break;
                     default:
                         throw new InvalidArgumentException('No default for property of type ' . $Type);
                 }
             }
             $this->_initialValues[$Name] = $this->{$Name};
         }
     }
 }