@@ -145,13 +145,11 @@ function writeSchema($conn, $tables) {
145
145
info ('Wrote /result/combined_schema.json ' );
146
146
}
147
147
148
- function dumpTable ($ conn , $ adapter , $ table ) {
149
- info ('Dumping ' . $ table );
150
-
151
- $ query = $ conn ->query ($ adapter ->selectSql ($ table ));
148
+ function dumpSql ($ conn , $ sql , $ filename ) {
149
+ $ query = $ conn ->query ($ sql );
152
150
$ query ->execute ();
153
151
154
- $ json = new CompressingJsonStreamFileWriter (' /result/data/ ' . $ table . ' .json.gz ' );
152
+ $ json = new CompressingJsonStreamFileWriter ($ filename );
155
153
$ json ->writer ->arrayBegin ();
156
154
157
155
$ rowCount = 0 ;
@@ -169,6 +167,12 @@ function dumpTable($conn, $adapter, $table) {
169
167
info ('Wrote ' . $ rowCount . ' rows to ' . $ json ->getPath ());
170
168
}
171
169
170
+ function dumpTable ($ conn , $ adapter , $ table ) {
171
+ info ('Dumping ' . $ table );
172
+
173
+ dumpSql ($ conn , $ adapter ->selectSql ($ table ), '/result/data/ ' . $ table . '.json.gz ' );
174
+ }
175
+
172
176
info ($ username !== '' ? 'Using username: ' . $ username : 'Username: (no username) ' );
173
177
info ($ password !== '' ? 'Using password: ******** ' : 'Password: (no password) ' );
174
178
info ('Connecting to DSN ' . $ dsn );
@@ -205,8 +209,19 @@ function dumpTable($conn, $adapter, $table) {
205
209
info ('Skipping schema fetch - only know how to do it for MySQL ' );
206
210
}
207
211
208
- foreach ($ tables as $ table ) {
209
- dumpTable ($ conn , $ adapter , $ table );
212
+ $ customSql = getenv ('SQL ' );
213
+
214
+ if ($ customSql ) {
215
+ info ("Custom SQL statement specified: $ customSql " );
216
+
217
+ dumpSql ($ conn , $ customSql , '/result/data/custom_ ' . time () . '.json.gz ' );
218
+ }
219
+ else {
220
+ foreach ($ tables as $ table ) {
221
+ dumpTable ($ conn , $ adapter , $ table );
222
+ }
223
+
224
+ info ('Exported ' . count ($ tables ) . ' tables ' );
210
225
}
211
226
212
- info ('Done, exported ' . count ( $ tables ) . ' tables ' );
227
+ info ('Done ' );
0 commit comments