SQL::procedure_list()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Query
4
 *
5
 * Free Query Builder / Database Abstraction Layer
6
 *
7
 * @package		Query
8
 * @author		Timothy J. Warren
9
 * @copyright	Copyright (c) 2012 - 2015
10
 * @link 		https://github.com/aviat4ion/Query
11
 * @license		http://philsturgeon.co.uk/code/dbad-license
12
 */
13
14
// --------------------------------------------------------------------------
15
16
namespace Query\Drivers\Sqlite;
17
18
/**
19
 * SQLite Specific SQL
20
 *
21
 * @package Query
22
 * @subpackage Drivers
23
 */
24
class SQL extends \Query\AbstractSQL {
25
26
	/**
27
	 * Get the query plan for the sql query
28
	 *
29
	 * @param string $sql
30
	 * @return string
31
	 */
32
	public function explain($sql)
33
	{
34
		return "EXPLAIN QUERY PLAN {$sql}";
35
	}
36
37
	// --------------------------------------------------------------------------
38
39
	/**
40
	 * Random ordering keyword
41
	 *
42
	 * @return string
43
	 */
44
	public function random()
45
	{
46
		return ' RANDOM()';
47
	}
48
49
	// --------------------------------------------------------------------------
50
51
	/**
52
	 * Returns sql to list other databases
53
	 *
54
	 * @return string
55
	 */
56
	public function db_list()
57
	{
58
		return 'PRAGMA database_list';
59
	}
60
61
	// --------------------------------------------------------------------------
62
63
	/**
64
	 * Returns sql to list tables
65
	 *
66
	 * @return string
67
	 */
68
	public function table_list()
69
	{
70
		return <<<SQL
71
			SELECT DISTINCT "name"
72
			FROM "sqlite_master"
73
			WHERE "type"='table'
74
			AND "name" NOT LIKE 'sqlite_%'
75
			ORDER BY "name" DESC
76
SQL;
77
	}
78
79
	// --------------------------------------------------------------------------
80
81
	/**
82
	 * List the system tables
83
	 *
84
	 * @return string[]
85
	 */
86
	public function system_table_list()
87
	{
88
		return array('sqlite_master', 'sqlite_temp_master', 'sqlite_sequence');
89
	}
90
91
	// --------------------------------------------------------------------------
92
93
	/**
94
	 * Returns sql to list views
95
	 *
96
	 * @return string
97
	 */
98
	public function view_list()
99
	{
100
		return <<<SQL
101
			SELECT "name" FROM "sqlite_master" WHERE "type" = 'view'
102
SQL;
103
	}
104
105
	// --------------------------------------------------------------------------
106
107
	/**
108
	 * Returns sql to list triggers
109
	 *
110
	 * @return string
111
	 */
112
	public function trigger_list()
113
	{
114
		return 'SELECT "name" FROM "sqlite_master" WHERE "type"=\'trigger\'';
115
	}
116
117
	// --------------------------------------------------------------------------
118
119
	/**
120
	 * Return sql to list functions
121
	 *
122
	 * @return NULL
123
	 */
124
	public function function_list()
125
	{
126
		return NULL;
127
	}
128
129
	// --------------------------------------------------------------------------
130
131
	/**
132
	 * Return sql to list stored procedures
133
	 *
134
	 * @return NULL
135
	 */
136
	public function procedure_list()
137
	{
138
		return NULL;
139
	}
140
141
	// --------------------------------------------------------------------------
142
143
	/**
144
	 * Return sql to list sequences
145
	 *
146
	 * @return NULL
147
	 */
148
	public function sequence_list()
149
	{
150
		return NULL;
151
	}
152
153
	// --------------------------------------------------------------------------
154
155
	/**
156
	 * SQL to show list of field types
157
	 *
158
	 * @return string[]
159
	 */
160
	public function type_list()
161
	{
162
		return array('INTEGER', 'REAL', 'TEXT', 'BLOB');
163
	}
164
165
	// --------------------------------------------------------------------------
166
167
	/**
168
	 * SQL to show infromation about columns in a table
169
	 *
170
	 * @param string $table
171
	 * @return string
172
	 */
173
	public function column_list($table)
174
	{
175
		return 'PRAGMA table_info("'.$table.'")';
176
	}
177
178
	// --------------------------------------------------------------------------
179
180
	/**
181
	 * Get the list of foreign keys for the current
182
	 * table
183
	 *
184
	 * @param string $table
185
	 * @return string
186
	 */
187
	public function fk_list($table)
188
	{
189
		return 'PRAGMA foreign_key_list("' . $table . '")';
190
	}
191
192
	// --------------------------------------------------------------------------
193
194
	/**
195
	 * Get the list of indexes for the current table
196
	 *
197
	 * @param string $table
198
	 * @return string
199
	 */
200
	public function index_list($table)
201
	{
202
		return 'PRAGMA index_list("' . $table . '")';
203
	}
204
205
}
206
//End of sqlite_sql.php