public string Query(QueryOutputType type, SQLiteCommand cmd) { switch (type) { case QueryOutputType.MarkdownTable: return(QueryToMarkdownTable(cmd)); case QueryOutputType.Scalar: return(QueryToScalar(cmd)?.ToString() ?? ""); case QueryOutputType.Csv: return(QueryToCsv(cmd)); default: throw new Exception("invalid QueryOutputType"); } }
public void SetOutputType(QueryOutputType outputType, string fileName = "") { switch (outputType) { case QueryOutputType.File: OutputToFile = fileName; break; case QueryOutputType.Text: case QueryOutputType.DataGrid: default: break; } }
public string RecallQuery(QueryOutputType type, string name, string[] args) { var cmd = CreateCommand(@"SELECT body FROM nquery_queries WHERE name = @name"); cmd.Parameters.AddWithValue("@name", name); var sql = cmd.ExecuteScalar()?.ToString(); if (sql == null) { throw new UserCommandException($"no such stored query: {name}"); } var cmd2 = CreateCommand(sql); cmd2.Parameters.AddWithValue("@0", String.Join(" ", args)); for (var i = 0; i < args.Length; i++) { cmd2.Parameters.AddWithValue($"@{i + 1}", args[i]); } return(Query(type, cmd2)); }