forked from duellj/sql_parser
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sql_parser.module
66 lines (58 loc) · 1.55 KB
/
sql_parser.module
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
<?php
// $Id$
/**
* @file
* Provides parsing ability from sql strings into Drupal DBTNG objects.
*/
/**
* Implements hook_menu.
*/
function sql_parser_menu() {
$items['sql-parser'] = array(
'title' => 'SQL Parser',
'page callback' => 'drupal_get_form',
'page arguments' => array('sql_parser_parser_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* Page Callback.
*/
function sql_parser_parser_form(&$form_state) {
if ($form_state['post']['sql']) {
$parsed_sql = sql_parser_parse($form_state['post']['sql']);
$query_string = sql_parser_convert($parsed_sql);
}
$form['sql'] = array(
'#title' => 'Original SQL String',
'#type' => 'textarea',
'#default_value' => $form_state['post']['sql'],
);
$form['output'] = array(
'#title' => 'Database Object',
'#type' => 'textarea',
'#rows' => 10,
'#attributes' => array(
'readonly' => 'readonly',
),
'#value' => $query_string,
);
$form['submit'] = array(
'#type' => 'button',
'#value' => t('Convert'),
);
return $form;
}
function sql_parser_parse($sql) {
module_load_include('inc', 'sql_parser', 'includes/sql_dialect');
module_load_include('inc', 'sql_parser', 'includes/sql_lexer');
module_load_include('inc', 'sql_parser', 'includes/sql_parser');
$parser = new SqlParser($sql);
return $parser->parse();
}
function sql_parser_convert($parsed_sql) {
module_load_include('inc', 'sql_parser', 'includes/sql_converter');
$converter = new SqlConverter($parsed_sql);
return $converter->convert();
}