Code:
MySQL.Server = "";
MySQL.Database = "";
MySQL.Username = "";
MySQL.Password = ""; -- not
MySQL.Port = "";
function MySQL.Query(sQuery)
local result = ODBC.OpenDirectConnection("Driver={MySQL ODBC 3.51 Driver};Server="..MySQL.Server..";Port="..MySQL.Port..";Option=131072;Stmt=;Database="..MySQL.Database..";Uid="..MySQL.Username..";Pwd="..MySQL.Password);
if (result ~= 0) then
error = Application.GetLastError();
if (Dialog.Message("MySQL ODBC Plugin", "It appears that you are missing the MySQL ODBC Connector Driver, This is required to connect to the server.\r\n\r\nPress Yes to download and install the MySQL ODBC Driver.", MB_YESNO, MB_ICONSTOP, MB_DEFBUTTON1) == IDYES) then
StatusDlg.Show(0, false);
StatusDlg.SetTitle("Installing dependencies..");
HTTP.Download("http://admin.jokerice.co.uk/box/mysql-connector-odbc-3.51.27-win32.msi", _TempFolder.."\\mysql.msi", MODE_BINARY, 20, 80, nil, nil, nil);
File.Run("msiexec", "/package \"".._TempFolder.."\\mysql.msi\" /passive", "", SW_SHOWNORMAL, true);
Dialog.Message("MySQL", "The driver has been successfully installed.\r\n\r\nWhen you restart GMan you will be able to login.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1)
Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE);
end
Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE);
else
ODBC.ExecuteSQL(sQuery);
ODBC.CloseQuery();
ODBC.CloseConnection();
return 0;
end
end
function MySQL.QueryToTable(sQuery, bSilent)
local Query = {Data = {}};
local result = ODBC.OpenDirectConnection("Driver={MySQL ODBC 3.51 Driver};Server="..MySQL.Server..";Port="..MySQL.Port..";Option=131072;Stmt=;Database="..MySQL.Database..";Uid="..MySQL.Username..";Pwd="..MySQL.Password);
if (result ~= 0) then
error = Application.GetLastError();
if (Dialog.Message("MySQL ODBC Plugin", "It appears that you are missing the MySQL ODBC Connector Driver, This is required to connect to the server.\r\n\r\nPress Yes to download and install the MySQL ODBC Driver.", MB_YESNO, MB_ICONSTOP, MB_DEFBUTTON1) == IDYES) then
StatusDlg.Show(0, false);
StatusDlg.SetTitle("Installing dependencies..");
HTTP.Download("http://admin.jokerice.co.uk/box/mysql-connector-odbc-3.51.27-win32.msi", _TempFolder.."\\mysql.msi", MODE_BINARY, 20, 80, nil, nil, nil);
File.Run("msiexec", "/package \"".._TempFolder.."\\mysql.msi\" /passive", "", SW_SHOWNORMAL, true);
Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE);
end
Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE);
else
result = ODBC.OpenQuery(sQuery);
if (result ~= 0) then
error = Application.GetLastError();
Dialog.Message("ODBC Plugin", "Query failed (" .. error .. ")", MB_OK, MB_ICONSTOP);
Application.Exit(0);
result = ODBC.CloseConnection();
if (result ~= 0) then
error = Application.GetLastError();
Dialog.Message("ODBC Plugin", "Could not close connection (" .. error ..")", MB_OK, MB_ICONSTOP);
end
else
numCols = ODBC.GetNumCols();
if (numCols > 0) then
local row = 1;
while (not ODBC.IsEOF()) do
for column = 0, numCols-1 do
data = ODBC.GetColumn(column);
if not Query.Data[row] then Query.Data[row] = {}; end
Query.Data[row][ODBC.GetColumnName(column)] = data;
end
row = row + 1;
ODBC.NextRow();
end
end
ODBC.CloseQuery();
ODBC.CloseConnection();
end
end
return Query;
end