Skip to content

Commit 0512e35

Browse files
committed
Merge branch '3.0' of git://github.com/thecodingmachine/database.querywriter into 3.0
2 parents 176e5fd + 7d06a92 commit 0512e35

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

src/Mouf/Database/QueryWriter/Controllers/SelectController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function getParameterizedQuery($name,$parameters,$selfedit="false") {
191191
* @param int $offset
192192
* @param int $limit
193193
*/
194-
public function runQuery($name, $parameters, $offset = null, $limit = null) {
194+
public function runQuery($name, $parameters = array(), $offset = null, $limit = null) {
195195
$select = new InstanceProxy($name);
196196
$sql = $select->toSql($parameters);
197197

src/SQLParser/Node/NodeFactory.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use SQLParser\Query\StatementFactory;
4242

4343
use SQLParser\ExpressionType;
44+
use Mouf\MoufException;
4445

4546
/**
4647
* This class has the ability to create instances implementing NodeInterface based on a descriptive array.
@@ -131,7 +132,35 @@ public static function toObject(array $desc) {
131132
case ExpressionType::TABLE:
132133
$expr = new Table();
133134
$expr->setTable(str_replace('`', '',$desc['table']));
134-
$expr->setJoinType($desc['join_type']);
135+
switch ($desc['join_type']) {
136+
case "CROSS":
137+
$joinType = "CROSS JOIN";
138+
break;
139+
case "JOIN":
140+
$joinType = "JOIN";
141+
break;
142+
case "LEFT":
143+
$joinType = "LEFT JOIN";
144+
break;
145+
case "RIGHT":
146+
$joinType = "RIGHT JOIN";
147+
break;
148+
case "INNER":
149+
$joinType = "INNER JOIN";
150+
break;
151+
case "OUTER":
152+
$joinType = "OUTER JOIN";
153+
break;
154+
case "NATURAL":
155+
$joinType = "NATURAL JOIN";
156+
break;
157+
case ",":
158+
$joinType = ",";
159+
break;
160+
default:
161+
throw new \Exception("Unexpected join type: '".$desc['join_type']."'");
162+
}
163+
$expr->setJoinType($joinType);
135164

136165
if (isset($desc['alias'])) {
137166
$expr->setAlias($desc['alias']['name']);

src/views/createQuery.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333

3434
</form>
3535

36+
<div class="alert">If you are performing JOINs, avoid doing a `SELECT * FROM ...`. You may have
37+
several columns with the same name in different tables and this might confuse QueryWritter, especially
38+
if you are using the `CountNbResult` class.</div>
39+
40+
3641
<script type="text/javascript">
3742
$(function () { $("input,select,textarea").not("[type=submit]").jqBootstrapValidation(); } );
3843
</script>

src/views/parseSql.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@
2121
</div>
2222
</div>
2323

24-
</form>
24+
</form>
25+
26+
<div class="alert">If you are performing JOINs, avoid doing a `SELECT * FROM ...`. You may have
27+
several columns with the same name in different tables and this might confuse QueryWritter, especially
28+
if you are using the `CountNbResult` class.</div>

src/views/tryQuery.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
<pre id="mainQuery"><code><?php echo $this->sql; ?></code></pre>
77

8+
<form action="" class="form-horizontal" id="parametersform">
9+
<input type="hidden" name="name" value="<?php echo plainstring_to_htmlprotected($this->instanceName); ?>" />
10+
811
<?php if (!empty($this->parameters)): ?>
912
<div class="row">
1013
<div class="span6">
1114
<h2>Configure parameters</h2>
1215

13-
<form action="" class="form-horizontal" id="parametersform">
14-
<input type="hidden" name="name" value="<?php echo plainstring_to_htmlprotected($this->instanceName); ?>" />
1516
<?php foreach ($this->parameters as $parameter) { ?>
1617
<div class="control-group">
1718
<label class="control-label"><?php echo plainstring_to_htmlprotected($parameter); ?>: </label>
@@ -20,7 +21,6 @@
2021
</div>
2122
</div>
2223
<?php } ?>
23-
</form>
2424
</div>
2525
<div class="span6">
2626
<h2>Query with parameters</h2>
@@ -54,10 +54,13 @@ function updateQuery() {
5454

5555
<div class="form-actions">
5656
<a href=".?name=<?php echo urlencode($this->instanceName) ?>" class="btn">&lt; Edit Query</a>
57-
<button type="button" class="btn btn-primary" id="runQueryButton">Run Query</button>
57+
<button type="submit" class="btn btn-primary" id="runQueryButton">Run Query</button>
5858
<a href="<?php echo ROOT_URL ?>ajaxinstance/?name=<?php echo urlencode($this->instanceName) ?>" class="btn">View instance &gt;</a>
5959
</div>
6060

61+
</form>
62+
63+
6164
<div id="resultsContainer"></div>
6265

6366
<script type="text/javascript">
@@ -73,9 +76,9 @@ function updateQuery() {
7376
});
7477
});
7578

76-
$("#runQueryButton").click(function() {
79+
/*$("#runQueryButton").click(function() {
7780
$("#parametersform").trigger("submit");
78-
});
81+
});*/
7982

8083
});
8184
</script>

0 commit comments

Comments
 (0)