string result = String.Empty;
string connectionString = project.Variables["connectionString"].Value;
string SQL = project.Variables["SQL"].Value;
var query = new DataTable();
try
{
using (var sqLiteConnection = new System.Data.SQLite.SQLiteConnection(connectionString))
{
sqLiteConnection.Open();
using (var cmd = new System.Data.SQLite.SQLiteCommand(sqLiteConnection) {CommandText = SQL})
{
var reader = cmd.ExecuteReader();
query.Load(reader);
}
}
}
catch(Exception ex)
{
project.SendErrorToLog(ex.Message, "sqlite error");
return result;
}
if (result != String.Empty) return result;
try
{
IZennoTable table = project.Tables["Table1"];
DataRow[] data = query.Select();
foreach (DataRow row in data)
{
if (!String.IsNullOrWhiteSpace(result)) {
result = String.Format("{0}\r\n{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}", result, row["field1"], row["field2"], row["field3"], row["field4"], row["field5"], row["field6"], row["field7"], row["field8"], row["field9"], row["field10"]);
table.AddRow(result);
result = String.Empty;
}
else {
result = String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}", row["field1"], row["field2"], row["field3"], row["field4"], row["field5"], row["field6"], row["field7"], row["field8"], row["field9"], row["field10"]);
table.AddRow(result);
result = String.Empty;
}
}
}
catch (System.Data.SQLite.SQLiteException e)
{
// словили
result = String.Format("SQLite reader exception: {0}", e.Message);
}
finally
{
// что бы не произошло закроем соединение
using (var sqLiteConnection = new System.Data.SQLite.SQLiteConnection(connectionString))
{
sqLiteConnection.Close();
}
}
// вернём результат
return result;