private void OpenDatabase(string fName) { if (database != null) { CloseDatabase(); } if (fName.Length > 0) { database = new SqliteDb(); int err = database.Open(fName); if (err != 0) { database = null; } } if (database != null) { databaseName = fName; treeView1.BeginUpdate(); // Clear the TreeView each time the method is called. treeView1.Nodes.Clear(); TreeNode databaseNode = new TreeNode(fName); SqliteVm vm = new SqliteVm(database, true); string tableList = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"; int fini = vm.Execute(tableList); while (fini == Sqlite.Row) { string tableName = vm.GetString("name"); databaseNode.Nodes.Add(tableName); fini = vm.NextRow(); } vm.SqlFinalize(); vm = null; treeView1.Nodes.Add(databaseNode); treeView1.EndUpdate(); //Enable menu items this.menuItem3.Enabled = true; this.menuAddTest.Enabled = true; this.saveAsMenuItem.Enabled = true; this.saveDbMenuItem.Enabled = true; } }
private static void AddLogFileEntry(ITestLogger logger, string operation, int paramSetId, SqliteVm vm) { logger.Write("\nParamSet: {0}\n", paramSetId); int status = vm.Execute("Select * from Params where ParamSet={0}", paramSetId); while (status == Sqlite.Row) { string paramName = vm.GetString("ParamName"); string paramValue = vm.GetString("ParamValue"); logger.Write("{0}: {1}\n", paramName, paramValue); status = vm.NextRow(); } }
public int Execute(ref int testsRun, ITestLogger logger, bool isEnterprise) { int exitStatus = 0; string dbPath = CommonUtility.GetDbPath(this.DumpFile); string dbName = CommonUtility.GetPath(dbPath); if (File.Exists(dbName)) { var db = new SqliteDb(); db.Open(dbName); var vm = new SqliteVm(db, true); int status = vm.Execute("Select TestName, TestType from TestCase where TestType=\"{0}\" order by ExecuteSequence", this.ApiType); //NOTE: We can't share the SqliteVm instance among our executor objects as this messes up query results //we must be able to re-create a new SqliteVm for each executor, so we pass down the db path SetupExecutors(dbName); while (status == Sqlite.Row) { string testName = vm.GetString("TestName"); string testType = vm.GetString("TestType"); Console.WriteLine("Executing {0} test: {1}", testType, testName); using (var run = new TestExecutionRun(dbPath, this)) { try { exitStatus += run.RunTests(testName, logger, ref testsRun); } catch (Exception ex) { Console.WriteLine(ex.ToString()); exitStatus += 1; } } status = vm.NextRow(); } vm.SqlFinalize(); vm = null; db = null; } return(exitStatus); }
public void LoadTable(SqliteDb newDatabase, string tableName) { this.Name = tableName; this.SetDatabase(newDatabase); DataGridTableStyle tableStyle = new DataGridTableStyle(); tableStyle.MappingName = tableName; if (tableName == "TestCase") { tableStyle.PreferredRowHeight *= 3; } else if (tableName == "ApiTestResults" || tableName == "HttpTestResults") { tableStyle.PreferredRowHeight *= 2; } int gridWidth = 0; vm = new SqliteVm(database, true); if (vm != null) { dataTable = new DataTable(tableName); string sql = String.Format("select rowid, * from {0} ;", tableName); int sqErr = vm.Execute(sql); int nCols = vm.NumCols(); for (int i = 0; i < nCols; i++) { string colName = vm.ColumnName(i); string colType = vm.ColumnType(colName); DataGridTextBoxColumn colStyle = new DataGridTextBoxColumn(); colStyle.MappingName = colName; colStyle.HeaderText = colName; switch (colType.ToUpper()) { case "INTEGER": dataTable.Columns.Add(colName, typeof(int)); colStyle.Width = 60; break; case "REAL": dataTable.Columns.Add(colName, typeof(double)); colStyle.Width = 60; break; case "TEXT": dataTable.Columns.Add(colName, typeof(string)); colStyle.TextBox.Multiline = true; if (colName == "ParamName" || colName == "ContentType" || colName == "TestType" || colName == "Prerequisite") { colStyle.Width = 100; } else if (colName == "ParamValue") { colStyle.Width = 275; } else { colStyle.Width = 200; } break; case "BLOB": DataColumn col = new DataColumn(colName, typeof(SqlBinary)); col.ReadOnly = true; dataTable.Columns.Add(col); colStyle.Width = 150; break; default: colStyle = null; break; } if (colStyle != null) { tableStyle.GridColumnStyles.Add(colStyle); gridWidth += colStyle.Width; } } //rowid should be readonly dataTable.Columns[0].ReadOnly = true; // update grid with new cols and width dataGrid1.TableStyles.Add(tableStyle); dataGrid1.Width = gridWidth; while (sqErr == Sqlite.Row) { object [] cols = new object[nCols]; for (int i = 0; i < nCols; i++) { string colName = vm.ColumnName(i); string colType = vm.ColumnType(colName); switch (colType.ToUpper()) { case "INTEGER": int colInt = vm.GetInt(colName); cols[i] = colInt; break; case "REAL": double colDbl = vm.GetDouble(colName); cols[i] = colDbl; break; case "TEXT": string colText = vm.GetString(colName); cols[i] = colText; break; case "BLOB": byte[] bytes = vm.GetBlob(colName).Read(); if (bytes != null) { SqlBinary binBlob = new SqlBinary(bytes); cols[i] = binBlob; } else { cols[i] = null; } break; default: break; } } dataTable.Rows.Add(cols); sqErr = vm.NextRow(); } } vm.SqlFinalize(); vm = null; dataTable.AcceptChanges(); dataGrid1.DataSource = dataTable; this.Width = gridWidth + 75; }
public int Execute(ref int testsRun, ITestLogger logger, bool isEnterprise) { int exitStatus = 0; string dbPath = CommonUtility.GetDbPath(this.DumpFile); string dbName = CommonUtility.GetPath(dbPath); if (File.Exists(dbName)) { var db = new SqliteDb(); db.Open(dbName); var vm = new SqliteVm(db, true); int status = vm.Execute("Select TestName, TestType from TestCase where TestType=\"{0}\" order by ExecuteSequence", this.ApiType); //NOTE: We can't share the SqliteVm instance among our executor objects as this messes up query results //we must be able to re-create a new SqliteVm for each executor, so we pass down the db path SetupExecutors(dbName); while (status == Sqlite.Row) { string testName = vm.GetString("TestName"); string testType = vm.GetString("TestType"); Console.WriteLine("Executing {0} test: {1}", testType, testName); using (var run = new TestExecutionRun(dbPath, this)) { try { exitStatus += run.RunTests(testName, logger, ref testsRun); } catch (Exception ex) { Console.WriteLine(ex.ToString()); exitStatus += 1; } } status = vm.NextRow(); } vm.SqlFinalize(); vm = null; db = null; } return exitStatus; }
public void LoadTable(SqliteDb newDatabase, string tableName) { this.Name = tableName; this.SetDatabase(newDatabase); DataGridTableStyle tableStyle = new DataGridTableStyle(); tableStyle.MappingName = tableName; if (tableName == "TestCase") { tableStyle.PreferredRowHeight *= 3; } else if (tableName == "ApiTestResults" || tableName == "HttpTestResults") { tableStyle.PreferredRowHeight *= 2; } int gridWidth = 0; vm = new SqliteVm(database, true); if (vm != null) { dataTable = new DataTable(tableName); string sql = String.Format("select rowid, * from {0} ;", tableName); int sqErr = vm.Execute(sql); int nCols = vm.NumCols(); for (int i = 0; i<nCols; i++) { string colName = vm.ColumnName(i); string colType = vm.ColumnType(colName); DataGridTextBoxColumn colStyle = new DataGridTextBoxColumn(); colStyle.MappingName = colName; colStyle.HeaderText = colName; switch (colType.ToUpper()) { case "INTEGER": dataTable.Columns.Add(colName, typeof(int)); colStyle.Width = 60; break; case "REAL": dataTable.Columns.Add(colName, typeof(double)); colStyle.Width = 60; break; case "TEXT": dataTable.Columns.Add(colName, typeof(string)); colStyle.TextBox.Multiline = true; if (colName == "ParamName" || colName == "ContentType" || colName == "TestType" || colName == "Prerequisite") { colStyle.Width = 100; } else if (colName == "ParamValue") { colStyle.Width = 275; } else { colStyle.Width = 200; } break; case "BLOB": DataColumn col = new DataColumn(colName, typeof(SqlBinary)); col.ReadOnly = true; dataTable.Columns.Add(col); colStyle.Width = 150; break; default: colStyle = null; break; } if (colStyle != null) { tableStyle.GridColumnStyles.Add(colStyle); gridWidth += colStyle.Width; } } //rowid should be readonly dataTable.Columns[0].ReadOnly = true; // update grid with new cols and width dataGrid1.TableStyles.Add(tableStyle); dataGrid1.Width = gridWidth; while (sqErr == Sqlite.Row) { object [] cols = new object[nCols]; for (int i=0; i<nCols; i++) { string colName = vm.ColumnName(i); string colType = vm.ColumnType(colName); switch (colType.ToUpper()) { case "INTEGER": int colInt = vm.GetInt(colName); cols[i] = colInt; break; case "REAL": double colDbl = vm.GetDouble(colName); cols[i] = colDbl; break; case "TEXT": string colText = vm.GetString(colName); cols[i] = colText; break; case "BLOB": byte[] bytes = vm.GetBlob(colName).Read(); if (bytes != null) { SqlBinary binBlob = new SqlBinary(bytes); cols[i] = binBlob; } else { cols[i] = null; } break; default: break; } } dataTable.Rows.Add(cols); sqErr = vm.NextRow(); } } vm.SqlFinalize(); vm = null; dataTable.AcceptChanges(); dataGrid1.DataSource = dataTable; this.Width = gridWidth+75; }