1: <?php
2: /**
3: * ManiaLive - TrackMania dedicated server manager in PHP
4: *
5: * @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
6: * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
7: * @version $Revision: 440 $:
8: * @author $Author: martin.gwendal $:
9: * @date $Date: 2012-08-17 12:03:09 +0200 (ven., 17 août 2012) $:
10: */
11:
12: namespace ManiaLive\Database\SQLite;
13:
14: class RecordSet extends \ManiaLive\Database\RecordSet
15: {
16: const FETCH_ASSOC = SQLITE3_ASSOC;
17: const FETCH_NUM = SQLITE3_NUM;
18: const FETCH_BOTH = SQLITE3_BOTH;
19:
20: /** @var \SQLite3Result */
21: protected $result;
22: /** @var bool */
23: protected $recordAvailable;
24:
25: function __construct($result)
26: {
27: $this->result = $result;
28: $this->recordAvailable = $this->result->fetchArray() !== false;
29: $this->result->reset();
30: }
31:
32: function fetchRow()
33: {
34: return $this->result->fetchArray(self::FETCH_NUM);
35: }
36:
37: function fetchAssoc()
38: {
39: return $this->result->fetchArray(self::FETCH_ASSOC);
40: }
41:
42: function fetchArray($resultType = self::FETCH_ASSOC)
43: {
44: return $this->result->fetchArray($resultType);
45: }
46:
47:
48: function fetchObject($className='\\stdClass', array $params=array())
49: {
50: $properties = $this->fetchAssoc();
51:
52: if(is_null($className))
53: {
54: $object = new stdClass();
55: }
56: else
57: {
58: // call to class' constructor must be done after filling the fields
59: $object = unserialize(sprintf('O:%d:"%s":0:{}', strlen($className), $className));
60: }
61:
62: $reflector = new \ReflectionObject($object);
63: foreach($properties as $key => $value)
64: {
65: try
66: {
67: $attribute = $reflector->getProperty($key);
68: $attribute->setAccessible(true);
69: $attribute->setValue($object, $value);
70: }
71: catch(\ReflectionException $e)
72: {
73: $object->$key = $value;
74: }
75: }
76:
77: // calling constructor
78: call_user_func_array(array($object, '__construct'), $params);
79:
80: return $object;
81: }
82:
83: function recordCount()
84: {
85: throw new \ManiaLive\Database\NotSupportedException();
86: }
87:
88: function recordAvailable()
89: {
90: return $this->recordAvailable;
91: }
92: }
93: ?>