Skip to content

Commit 5240d58

Browse files
committed
init
0 parents  commit 5240d58

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

plugin/db.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
if(isset($argv[1]) && $argv[1] != '')
4+
{
5+
$all_names = [];
6+
7+
$word = $argv[5];
8+
$database = $argv[4];
9+
$password = $argv[3];
10+
$user = $argv[2];
11+
$host = $argv[1];
12+
13+
$dblink = mysqli_connect($host, $user, $password, $database);
14+
15+
if($word == 'prefixes')
16+
{
17+
$sql_statement = "SELECT count(*) AS total FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '".$database."' AND ( COLUMN_NAME LIKE '".$argv[6]."%' )";
18+
$result = $dblink->query($sql_statement);
19+
$data = mysqli_fetch_array($result);
20+
21+
if($data['total'])
22+
{
23+
echo 1;
24+
}
25+
exit;
26+
}
27+
else if(strpos($word,'.'))
28+
{
29+
$words = explode('.',$word);
30+
$sql_statement = "SELECT COLUMN_NAME,TABLE_NAME,COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '".$database."' AND ( COLUMN_NAME LIKE '".$words[1]."%' AND TABLE_NAME = '".$words[0]."' )";
31+
32+
$result = $dblink->query($sql_statement);
33+
while($row = mysqli_fetch_array($result))
34+
{
35+
$all_names[$row['TABLE_NAME'].'.'.$row['COLUMN_NAME']] = $row['TABLE_NAME'].'.'.$row['COLUMN_NAME'].'//'.$row['COLUMN_TYPE'];
36+
}
37+
}
38+
else
39+
{
40+
$sql_statement = "SELECT COLUMN_NAME,TABLE_NAME,COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '".$database."' AND ( COLUMN_NAME LIKE '".$word."%' OR TABLE_NAME LIKE '".$word."%' )";
41+
42+
$result = $dblink->query($sql_statement);
43+
while($row = mysqli_fetch_array($result))
44+
{
45+
if(strpos($row['COLUMN_NAME'],$word) === 0)
46+
{
47+
$all_names[$row['COLUMN_NAME']] = $row['COLUMN_NAME'].'/'.$row['TABLE_NAME'].'/'.$row['COLUMN_TYPE'];
48+
}
49+
if(strpos($row['TABLE_NAME'],$word) === 0)
50+
{
51+
$all_names[$row['TABLE_NAME']] = $row['TABLE_NAME'].'//table';
52+
}
53+
}
54+
}
55+
56+
57+
58+
mysqli_close($dblink);
59+
echo implode(';', $all_names);
60+
}

plugin/vim-mysql-suggestions.vim

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
let g:path_myslq_plugin = expand('<sfile>:p:h')
3+
4+
function! MyCompleteFunction( findstart, base )
5+
if a:findstart
6+
let line = getline('.')
7+
let start = col('.') - 1
8+
while start > 0 && line[start - 1] =~ '[A-Za-z_.]'
9+
let start -= 1
10+
endwhile
11+
return start
12+
else
13+
let command = "!php ".g:path_myslq_plugin."/db.php '".g:database_host."' '".g:database_user."' '".g:database_password."' '".g:database_database."' '".a:base."'"
14+
redir =>output
15+
silent! exe command
16+
redir END
17+
let lenght = strlen(command)
18+
let lenght = lenght + 4
19+
let outputLenght = strlen(output)
20+
let matches = split(output[ lenght : outputLenght ], ";")
21+
let result = []
22+
for i in matches
23+
let exploded = split(i, "/")
24+
call add(result, {'word' : exploded[0], 'kind' : exploded[2], 'menu' : exploded[1]}) ", 'info': 'int'
25+
endfor
26+
return result
27+
endif
28+
endfunction
29+
30+
31+
function! DatabasePrefixesInit(word)
32+
let command = "!php ".g:path_myslq_plugin."/db.php '".g:database_host."' '".g:database_user."' '".g:database_password."' '".g:database_database."' 'prefixes' '".a:word."'"
33+
redir =>output
34+
silent! exe command
35+
redir END
36+
let lenght = strlen(command)
37+
let lenght = lenght + 4
38+
let outputLenght = strlen(output)
39+
return output[lenght:outputLenght]
40+
endfunction
41+
42+

0 commit comments

Comments
 (0)