|
1
|
|
|
<?php |
|
2
|
|
|
namespace AlgoWeb\ModelViews\Database; |
|
3
|
|
|
|
|
4
|
|
|
use Illuminate\Database\Connection as BaseConnection; |
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
|
|
7
|
|
|
class Connection extends BaseConnection |
|
|
|
|
|
|
8
|
|
|
{ |
|
9
|
|
|
protected static $classes = []; |
|
10
|
|
|
|
|
11
|
|
|
protected static $information_schema = []; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
public static function RegisterTableToProvide($ModelOfTable) |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
self::$classes[] = $ModelOfTable; |
|
|
|
|
|
|
16
|
|
|
$currentISchemaTables = 0; |
|
17
|
|
|
if(array_key_exists("tables",self::$information_schema)){ |
|
|
|
|
|
|
18
|
|
|
$currentISchemaTables = count(self::$information_schema["tables"]); |
|
|
|
|
|
|
19
|
|
|
} else { |
|
20
|
|
|
self::$information_schema["tables"] = []; |
|
|
|
|
|
|
21
|
|
|
} |
|
22
|
|
|
self::$information_schema["tables"][$currentISchemaTables]["Model"] = $ModelOfTable; |
|
|
|
|
|
|
23
|
|
|
self::$information_schema["tables"][$currentISchemaTables]["TABLE_NAME"] = $ModelOfTable::getTableName(); |
|
|
|
|
|
|
24
|
|
|
self::$information_schema["tables"][$currentISchemaTables]["TABLE_SCHEMA"] = \Config::get('database.connections.'.\Config::get('database.default').'.database'); |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
protected $normalizer; |
|
28
|
|
|
/** |
|
29
|
|
|
* Run a select statement and return a single result. |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $query |
|
32
|
|
|
* @param array $bindings |
|
33
|
|
|
* @return mixed |
|
34
|
|
|
*/ |
|
35
|
|
|
public function selectOne($query, $bindings = array()) |
|
36
|
|
|
{ |
|
37
|
|
|
$records = parent::select($query, $bindings); |
|
|
|
|
|
|
38
|
|
|
return $records; |
|
39
|
|
|
} |
|
40
|
|
|
/** |
|
41
|
|
|
* Run a select statement against the database. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $query |
|
44
|
|
|
* @param array $bindings |
|
45
|
|
|
* @return \Stidges\LaravelDbNormalizer\Collection |
|
|
|
|
|
|
46
|
|
|
*/ |
|
47
|
|
|
public function select($query, $bindings = array()) |
|
48
|
|
|
{ |
|
49
|
|
|
|
|
50
|
|
|
//dd(self::$information_schema); |
|
|
|
|
|
|
51
|
|
|
dd(self::getSQL($query,$bindings)); |
|
52
|
|
|
$records = parent::select($query, $bindings); |
|
53
|
|
|
dd($records); |
|
54
|
|
|
return $records; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function ProcessSQL($query,$results){ |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
private static function getSQL($sql, $bindings) |
|
62
|
|
|
{ |
|
63
|
|
|
$needle = '?'; |
|
64
|
|
|
foreach ($bindings as $replace){ |
|
65
|
|
|
$pos = strpos($sql, $needle); |
|
66
|
|
|
if ($pos !== false) { |
|
67
|
|
|
if (gettype($replace) === "string") { |
|
|
|
|
|
|
68
|
|
|
$replace = ' "'.addslashes($replace).'" '; |
|
69
|
|
|
} |
|
70
|
|
|
$sql = substr_replace($sql, $replace, $pos, strlen($needle)); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
return $sql; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.