This repository was archived by the owner on Feb 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSqlDataQuery.php
More file actions
156 lines (135 loc) · 3.63 KB
/
SqlDataQuery.php
File metadata and controls
156 lines (135 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
namespace exface\SqlDataConnector;
use exface\Core\CommonLogic\DataQueries\AbstractDataQuery;
use exface\SqlDataConnector\Interfaces\SqlDataConnectorInterface;
use exface\Core\Factories\WidgetFactory;
use exface\Core\Widgets\DebugMessage;
class SqlDataQuery extends AbstractDataQuery
{
private $sql = '';
private $result_array = null;
private $result_resource = null;
private $connection = null;
/**
*
* @return string
*/
public function getSql()
{
return $this->sql;
}
/**
*
* @param string $value
* @return \exface\Core\CommonLogic\DataQueries\SqlDataQuery
*/
public function setSql($value)
{
$this->sql = $value;
return $this;
}
public function getResultArray()
{
if (is_null($this->result_array)) {
return $this->getConnection()->makeArray($this);
}
return $this->result_array;
}
public function setResultArray(array $value)
{
$this->result_array = $value;
return $this;
}
public function getResultResource()
{
return $this->result_resource;
}
public function setResultResource($value)
{
$this->result_resource = $value;
return $this;
}
/**
*
* {@inheritdoc}
*
* @see \exface\Core\CommonLogic\DataQueries\AbstractDataQuery::importString()
*/
public function importString($string)
{
$this->setSql($string);
}
/**
*
* {@inheritdoc}
*
* @see \exface\Core\CommonLogic\DataQueries\AbstractDataQuery::exportUxonObject()
*/
public function exportUxonObject()
{
$uxon = parent::exportUxonObject();
$uxon->setProperty('sql', $this->getSql());
return $uxon;
}
/**
*
* {@inheritdoc}
*
* @see \exface\Core\Interfaces\DataSources\DataQueryInterface::countAffectedRows()
*/
public function countAffectedRows()
{
return $this->getConnection()->getAffectedRowsCount($this);
}
public function getLastInsertId()
{
return $this->getConnection()->getInsertId($this);
}
/**
*
* @return \exface\SqlDataConnector\Interfaces\SqlDataConnectorInterface
*/
public function getConnection()
{
return $this->connection;
}
public function setConnection(SqlDataConnectorInterface $value)
{
$this->connection = $value;
return $this;
}
public function freeResult()
{
$this->getConnection()->freeResult($this);
}
/**
*
* {@inheritdoc}
*
* @see \exface\Core\CommonLogic\DataQueries\AbstractDataQuery::toString()
*/
public function toString()
{
return \SqlFormatter::format($this->getSql(), false);
}
/**
*
* {@inheritdoc} The SQL query creates a debug panel showing a formatted SQL statement.
*
* @see \exface\Core\CommonLogic\DataQueries\AbstractDataQuery::createDebugWidget()
*/
public function createDebugWidget(DebugMessage $debug_widget)
{
$page = $debug_widget->getPage();
$sql_tab = $debug_widget->createTab();
$sql_tab->setCaption('SQL');
$sql_tab->setNumberOfColumns(1);
/* @var $sql_widget \exface\Core\Widgets\Html */
$sql_widget = WidgetFactory::create($page, 'Html', $sql_tab);
$sql_widget->setValue('<div style="padding:10px;">' . \SqlFormatter::format($this->getSql()) . '</div>');
$sql_widget->setWidth('100%');
$sql_tab->addWidget($sql_widget);
$debug_widget->addTab($sql_tab);
return $debug_widget;
}
}