Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
borissov committed Jul 21, 2016
0 parents commit 5240d58
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
60 changes: 60 additions & 0 deletions plugin/db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

if(isset($argv[1]) && $argv[1] != '')
{
$all_names = [];

$word = $argv[5];
$database = $argv[4];
$password = $argv[3];
$user = $argv[2];
$host = $argv[1];

$dblink = mysqli_connect($host, $user, $password, $database);

if($word == 'prefixes')
{
$sql_statement = "SELECT count(*) AS total FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '".$database."' AND ( COLUMN_NAME LIKE '".$argv[6]."%' )";
$result = $dblink->query($sql_statement);
$data = mysqli_fetch_array($result);

if($data['total'])
{
echo 1;
}
exit;
}
else if(strpos($word,'.'))
{
$words = explode('.',$word);
$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]."' )";

$result = $dblink->query($sql_statement);
while($row = mysqli_fetch_array($result))
{
$all_names[$row['TABLE_NAME'].'.'.$row['COLUMN_NAME']] = $row['TABLE_NAME'].'.'.$row['COLUMN_NAME'].'//'.$row['COLUMN_TYPE'];
}
}
else
{
$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."%' )";

$result = $dblink->query($sql_statement);
while($row = mysqli_fetch_array($result))
{
if(strpos($row['COLUMN_NAME'],$word) === 0)
{
$all_names[$row['COLUMN_NAME']] = $row['COLUMN_NAME'].'/'.$row['TABLE_NAME'].'/'.$row['COLUMN_TYPE'];
}
if(strpos($row['TABLE_NAME'],$word) === 0)
{
$all_names[$row['TABLE_NAME']] = $row['TABLE_NAME'].'//table';
}
}
}



mysqli_close($dblink);
echo implode(';', $all_names);
}
42 changes: 42 additions & 0 deletions plugin/vim-mysql-suggestions.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

let g:path_myslq_plugin = expand('<sfile>:p:h')

function! MyCompleteFunction( findstart, base )
if a:findstart
let line = getline('.')
let start = col('.') - 1
while start > 0 && line[start - 1] =~ '[A-Za-z_.]'
let start -= 1
endwhile
return start
else
let command = "!php ".g:path_myslq_plugin."/db.php '".g:database_host."' '".g:database_user."' '".g:database_password."' '".g:database_database."' '".a:base."'"
redir =>output
silent! exe command
redir END
let lenght = strlen(command)
let lenght = lenght + 4
let outputLenght = strlen(output)
let matches = split(output[ lenght : outputLenght ], ";")
let result = []
for i in matches
let exploded = split(i, "/")
call add(result, {'word' : exploded[0], 'kind' : exploded[2], 'menu' : exploded[1]}) ", 'info': 'int'
endfor
return result
endif
endfunction


function! DatabasePrefixesInit(word)
let command = "!php ".g:path_myslq_plugin."/db.php '".g:database_host."' '".g:database_user."' '".g:database_password."' '".g:database_database."' 'prefixes' '".a:word."'"
redir =>output
silent! exe command
redir END
let lenght = strlen(command)
let lenght = lenght + 4
let outputLenght = strlen(output)
return output[lenght:outputLenght]
endfunction


0 comments on commit 5240d58

Please sign in to comment.