public CGIResponseData GetData(string[] commandline) { if (commandline == null || commandline.Length != 2) { return(new CGIResponseData("Error in command line. " + UsageText)); } try { InitThreadContext(); var commandtype = commandline[0].ToLowerInvariant(); var commandtext = commandline[1]; using (var connection = new PqlDataConnection()) { connection.ConnectionString = ConnectionString; connection.Open(); var cmd = connection.CreateCommand(); cmd.CommandText = commandtext; if (commandtype == "prepare") { cmd.Prepare(); return(new CGIResponseData("Prepared.")); } if (commandtype == "u") { var raff = cmd.ExecuteNonQuery(); return(new CGIResponseData("Update complete. Affected records: " + raff)); } if (commandtype == "q") { using (var reader = cmd.ExecuteReader()) { return(new CGIResponseData(reader)); } } return(new CGIResponseData("Invalid command type: " + commandtype + ". " + UsageText)); } } catch (Exception e) { return(new CGIResponseData(e.Message)); } }
public void TestDummyData() { try { using (var conn = new PqlDataConnection()) { conn.ConnectionString = "Server=localhost:5000/default;Initial Catalog=1:1"; var cmd = conn.CreateCommand(); for (var i = 0; i < 100000; i++) { { //cmd.CommandText = "select field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11,field12,field13,field14,field15,field16,field17,field18,field19,field20 from testDoc where field3+2=3 and field4 in ('1',field5) order by field6 desc"; cmd.CommandText = "select * from testDoc"; ConsumePregeneratedData(cmd, false); } } } } catch (Exception e) { Console.WriteLine(e); } }
static void GetSomeData(string commandText) { try { using (var conn = new PqlDataConnection()) { conn.ConnectionString = ConnectionString; var cmd = conn.CreateCommand(); cmd.CommandText = commandText; var timer1 = Stopwatch.StartNew(); var timer2 = Stopwatch.StartNew(); var count = 0; using (var reader = cmd.ExecuteReader()) { timer1.Stop(); var formatString = CreateFormatString(reader); var normalColor = Console.ForegroundColor; var nullValueColor = ConsoleColor.DarkGray; while (reader.Read()) { count++; Console.WriteLine("---------------------"); for (var ordinal = 0; ordinal < reader.FieldCount; ordinal++) { Console.Write(formatString, ordinal, reader.GetName(ordinal), reader.GetFieldType(ordinal).Name); if (reader.IsDBNull(ordinal)) { Console.ForegroundColor = nullValueColor; Console.WriteLine("<null>"); Console.ForegroundColor = normalColor; } else { Console.WriteLine(reader.GetValue(ordinal)); } if (Console.KeyAvailable) { Console.ReadKey(true); throw new Exception("Key pressed, dataset traversal aborted"); } } } timer2.Stop(); } Console.WriteLine("---------------------"); Console.WriteLine("{0} records, {1} ms to initiate, {2} ms to complete", count, timer1.ElapsedMilliseconds, timer2.ElapsedMilliseconds); } } catch (Exception e) { var oldColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(e.ToString()); Console.ForegroundColor = oldColor; } }
public CGIResponseData GetData(string[] commandline) { if (commandline == null || commandline.Length != 2) { return new CGIResponseData("Error in command line. " + UsageText); } try { InitThreadContext(); var commandtype = commandline[0].ToLowerInvariant(); var commandtext = commandline[1]; using (var connection = new PqlDataConnection()) { connection.ConnectionString = ConnectionString; connection.Open(); var cmd = connection.CreateCommand(); cmd.CommandText = commandtext; if (commandtype == "prepare") { cmd.Prepare(); return new CGIResponseData("Prepared."); } if (commandtype == "u") { var raff = cmd.ExecuteNonQuery(); return new CGIResponseData("Update complete. Affected records: " + raff); } if (commandtype == "q") { using (var reader = cmd.ExecuteReader()) { return new CGIResponseData(reader); } } return new CGIResponseData("Invalid command type: " + commandtype + ". " + UsageText); } } catch (Exception e) { return new CGIResponseData(e.Message); } }