public TestExecutionRun(string dbPath, ITestExecutorCollection exec, bool generateDump = false) { _executors = exec; _generateDump = generateDump; _unitTestDb = new SqliteDb(); _unitTestDb.Open(dbPath); _unitTestVm = new SqliteVm(_unitTestDb, false); _unitTestResultVm = new SqliteVm(_unitTestDb, false); }
public override void Dispose() { _unitTestVm.SqlFinalize(); _unitTestVm = null; try { _unitTestDb.Close(); } catch { } _unitTestDb = null; }
protected PlatformApiTestExecutor(string opName, string apiType, string unitTestVm) { _opName = opName; _apiType = apiType; _unitTestVmPath = unitTestVm; _unitTestDb = new SqliteDb(); _unitTestDb.Open(_unitTestVmPath); _unitTestVm = new SqliteVm(_unitTestDb, true); }
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 void TestUndoRemoveNodeChain() { var command = CreateCommandForNewDb("Tester.rootcause"); Dictionary <string, Node> nodes = CreateComplexModelForTest(); SqliteDb.GetInstance().RemoveNodeChain(nodes["Node 1.2"]); SqliteDb.GetInstance().UndoRemoveNodeChain(nodes["Node 1.2"], new Node[1] { nodes["Problem"] }); VerifyDefaultComplexModel(command, nodes); CleanUpCommand(command); }
public void Dispose() { _unitTestResultVm.SqlFinalize(); _unitTestResultVm = null; _unitTestVm.SqlFinalize(); _unitTestVm = null; try { _unitTestDb.Close(); } catch { } _unitTestDb = null; }
public IHttpContext InsertTestProject(IHttpContext ctx) { MProject test = new MProject(); test.ProjectVersion = 1337; test.Author = "TestAuthor"; test.ProjectName = "A Testproject"; test.Created = DateTime.Now; test.LastChanged = DateTime.Now; long id = SqliteDb.InsertProject(test); test.ProjectID = (int)id; HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, JsonConvert.SerializeObject(test, Formatting.Indented)); return(ctx); }
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 DeleteProblem() { try { new RemoveNodeChainCommand(SqliteDb.GetInstance(), currentProblem.InitialProblem, true); } catch (System.Data.SQLite.SQLiteException) { ProcessConnectionLost(); } catch (Exception) { throw; } Problems.Remove(currentProblem); currentProblem = null; GenerateGraph(); }
private void TestRemoveTopLevel() { var command = CreateCommandForNewDb("Tester.rootcause"); Dictionary <string, Node> nodes = CreateComplexModelForTest(); SqliteDb.GetInstance().RemoveTopLevel(nodes["Problem"]); var expectedLinks = new Node[0, 2] { }; TestHierarchy(command, expectedLinks); var expectedNodes = new Node[0] { }; TestNodes(command, expectedNodes); CleanUpCommand(command); }
private async Task LoadAllPeople(string caller, Action callBack) { var allResult = await SqliteDb.GetAll <Person>(); if (allResult.Error == null) { People = allResult.Response.ToObservable <Person>(); callBack?.Invoke(); } else { DialogPrompt.ShowMessage(new Prompt() { Title = "Error", Message = allResult.Error.Message }); } }
private void TestLoadFile() { CreateCommandForNewDb("Tester.rootcause").Dispose(); CreateComplexModelForTest(); IEnumerable <ProblemContainer> problems = SqliteDb.GetInstance().LoadFile(GetPath("Tester.rootcause")); HashSet <string> links = new HashSet <string>(); Func <HashSet <string>, Node, int> fillLinks = null; fillLinks = (HashSet <string> listOfLinks, Node parent) => { int linkCount = 0; foreach (var child in parent.ChildNodes) { if (listOfLinks.Add($"{parent.Text} links to {child.Text}")) { linkCount++; } linkCount = linkCount + fillLinks(listOfLinks, child); } return(linkCount); }; int totalLinks = 0; foreach (var problem in problems) { totalLinks = fillLinks(links, problem.InitialProblem); } Assert.AreEqual(10, totalLinks); Assert.IsTrue(links.Contains("Problem links to Node 1.1")); Assert.IsTrue(links.Contains("Problem links to Node 1.2")); Assert.IsTrue(links.Contains("Node 1.1 links to Node 2.1")); Assert.IsTrue(links.Contains("Node 1.2 links to Node 2.1")); Assert.IsTrue(links.Contains("Node 1.2 links to Node 2.2")); Assert.IsTrue(links.Contains("Node 1.2 links to Node 2.3")); Assert.IsTrue(links.Contains("Node 2.1 links to Node 3.1")); Assert.IsTrue(links.Contains("Node 2.2 links to Node 3.1")); Assert.IsTrue(links.Contains("Node 2.2 links to Node 3.2")); Assert.IsTrue(links.Contains("Node 2.3 links to Node 3.2")); }
public override void OnInit() { Task.Run(async() => { var results = await SqliteDb.GetAll <Person>(); if (results.Success) { People = results.Response.ToObservable(); } else { DialogPrompt.ShowMessage(new Prompt() { Title = "Error", Message = results.Error.Message, ButtonTitles = new string[] { "Okay" } }); } }); }
private void SaveDatabase() { if (!this.addTestForm.IsDisposed) { this.addTestForm.Dispose(); } if (database != null) { string dbName = database.GetName(); if (!IsReadOnly(dbName)) { this.CloseForms(); } else { //If the file is read only show a warning message and if the user wants, make the file writeable string errMsg = String.Format("File {0} is read only! \nOverwrite it?", dbName); DialogResult result = System.Windows.Forms.MessageBox.Show(errMsg, "Error", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Hand, System.Windows.Forms.MessageBoxDefaultButton.Button1); if (DialogResult.Yes == result) { FileInfo dbFile = new FileInfo(dbName); dbFile.Attributes = FileAttributes.Archive; //Hack...if the database is not read only we can write to it. //Nevertheles, if the ReadOnly property has changed after the database handler was created //then, we need to re-create it or SQLite will throw exception database.Close(); database = new SqliteDb(); database.Open(dbName); this.CloseForms(); } } } }
public IHttpContext LoadProject(IHttpContext ctx) { if (ctx.Request.QueryString["projectid"] == null) { HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, "{\"status\": \"error\", \"reason\": \"not found\"}"); return(ctx); } MProject p = SqliteDb.GetProject(Int32.Parse(ctx.Request.QueryString["projectid"])); XBimParser parsival = new XBimParser(p.FileName); parsival.LoadGeometry(); if (parsival.HasLoaded()) { sessions.Add(sessionCounter, parsival); HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, "{\"status\": \"success\", \"session\": " + sessionCounter.ToString() + "}"); sessionCounter++; } return(ctx); }
public SomeViewModel() { People = new ObservableCollection <Person>(); AddPerson = new CoreCommand(async(obj) => { var p = new Person() { FirstName = this.FirstName, LastName = this.LastName, DOB = DateTime.Now }; var result = await SqliteDb.AddOrUpdate <Person>(p); if (result.Success) { People.Add(p); FirstName = string.Empty; LastName = string.Empty; await CoreSettings.AppNav.PopAsync(); } }); }
private void TestChangeNodeText() { var command = CreateCommandForNewDb("Tester.rootcause"); var problem = NodeFactory.CreateProblem("Problem", SequentialId.NewId()); SqliteDb.GetInstance().InsertTopLevel(problem); SqliteDb.GetInstance().ChangeNodeText(problem, "This is my problem"); string sql = $"SELECT * FROM nodes WHERE nodeid = '{problem.NodeId}';"; command.CommandText = sql; SQLiteDataReader reader = command.ExecuteReader(); reader.Read(); string newText = reader["nodetext"].ToString(); reader.Close(); CleanUpCommand(command); Assert.AreEqual("This is my problem", newText); }
private void TestUndoRemoveFinalLink() { var command = CreateCommandForNewDb("Tester.rootcause"); Dictionary <string, Node> nodes = CreateComplexModelForTest(); SqliteDb.GetInstance().RemoveLink(nodes["Problem"], nodes["Node 1.2"]); SqliteDb.GetInstance().UndoRemoveLink(nodes["Problem"], nodes["Node 1.2"]); var expectedLinks = new Node[10, 2] { { nodes["Problem"], nodes["Node 1.1"] }, { nodes["Problem"], nodes["Node 1.2"] }, { nodes["Node 1.1"], nodes["Node 2.1"] }, { nodes["Node 1.2"], nodes["Node 2.1"] }, { nodes["Node 1.2"], nodes["Node 2.2"] }, { nodes["Node 1.2"], nodes["Node 2.3"] }, { nodes["Node 2.1"], nodes["Node 3.1"] }, { nodes["Node 2.2"], nodes["Node 3.1"] }, { nodes["Node 2.2"], nodes["Node 3.2"] }, { nodes["Node 2.3"], nodes["Node 3.2"] } }; TestHierarchy(command, expectedLinks); var expectedNodes = new Node[8] { nodes["Problem"], nodes["Node 1.1"], nodes["Node 1.2"], nodes["Node 2.1"], nodes["Node 2.2"], nodes["Node 2.3"], nodes["Node 3.1"], nodes["Node 3.2"] }; TestNodes(command, expectedNodes); CleanUpCommand(command); }
public override void OnViewMessageReceived(string key, object obj) { if (key == CoreSettings.DeletePersonTag && obj != null) { var pk = (string)obj; SqliteDb.DeleteByQuery <Person>(x => x.Id == pk).ContinueWith(async(t) => { var deleteResult = t.Result; if (deleteResult.Success) { await LoadAllPeople("OnViewMessageReceived", null); } else { DialogPrompt.ShowMessage(new Prompt() { Title = "Error", Message = deleteResult.Error.Message }); } }); } }
private void TestRemoveLink() { var command = CreateCommandForNewDb("Tester.rootcause"); var problem = NodeFactory.CreateProblem("Problem", SequentialId.NewId()); var node1 = NodeFactory.CreateCause("Node 1", SequentialId.NewId()); var node2 = NodeFactory.CreateCause("Node 2", SequentialId.NewId()); SqliteDb.GetInstance().InsertTopLevel(problem); SqliteDb.GetInstance().AddNode(problem, node1); SqliteDb.GetInstance().AddNode(node1, node2); SqliteDb.GetInstance().AddLink(problem, node2); SqliteDb.GetInstance().RemoveLink(problem, node2); var expectedLinks = new Node[2, 2] { { problem, node1 }, { node1, node2 } }; TestHierarchy(command, expectedLinks); CleanUpCommand(command); }
static void Main() { if (!Proceed()) { MessageBox.Show("Unlicensed Product. \nCall on : 9879539134 to get valid license", "Unlicensed Product", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } try { string GUID = Assembly.GetExecutingAssembly().GetType().GUID.ToString(); using (Mutex mutex = new Mutex(false, @"Global\" + GUID)) { if (!mutex.WaitOne(0, false)) { MessageBox.Show("GST Billing Software is already running.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } GC.Collect(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SqliteDb objSqlLite = new SqliteDb(); objSqlLite.CreateDatabase(); Application.Run(new Login()); } } catch (Exception ex) { Console.WriteLine(ex.Message); MessageBox.Show("An unexpected error occured. Please restart the application.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } }
public IHttpContext PostProject(IHttpContext ctx) { if (ctx.Request.HasEntityBody) { int chunksize = 1024; using (Stream input = ((HttpRequest)ctx.Request).Advanced.InputStream) { var parser = MultipartFormDataParser.Parse(input); foreach (FilePart file in parser.Files) { using (BinaryReader reader = new BinaryReader(file.Data, ctx.Request.ContentEncoding)) { string filename = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() + ".ifc"; string storagefile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Storage", filename); using (BinaryWriter output = new BinaryWriter(File.Open(storagefile, FileMode.Create))) { byte[] chunk = reader.ReadBytes(chunksize); while (chunk.Length > 0) { output.Write(chunk); chunk = reader.ReadBytes(chunksize); } } //ifc file available here XBimParser xbparse = new XBimParser(storagefile); MProject mp = xbparse.GetProject(); SqliteDb.InsertProject(mp); HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, "{\"status\": \"success\"}"); } } } } return(ctx); }
public static NameValueCollection SetCommonParams(int paramSet, SqliteDb db) { NameValueCollection result = null; var vm = new SqliteVm(db, false); try { result = new NameValueCollection(); vm.ReadParameterValue(paramSet, "OPERATION", result); vm.ReadCommonParameterValue("VERSION", result); vm.ReadCommonParameterValue("CREDENTIALS", result); vm.ReadCommonParameterValue("LOCALE", result); vm = null; } catch (MgException ex) { throw new UnitTestException(string.Format("Exception from MapGuide:\n{0}", ex.GetDetails())); } catch (Exception ex) { try { vm = null; vm = new SqliteVm(db, true); vm.ReadParameterValue("VERSION", result); vm.ReadParameterValue("CREDENTIALS", result); vm.ReadParameterValue("LOCALE", result); } catch (Exception ex2) { } } return(result); }
public void EditNodeText(string text, Node parent) { ExecuteCommand(new ChangeNodeTextCommand(SqliteDb.GetInstance(), parent, text)); }
public void SetDatabase(SqliteDb newDatabase) { this.database = newDatabase; }
public void RemoveLink(Node parent, Node child) { ExecuteCommand(new RemoveLinkCommand(SqliteDb.GetInstance(), parent, child)); }
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; }
/* ** Finalize and free a list of prepared statements */ static void flushStmtCache( SqliteDb pDb ) { SqlPreparedStmt pPreStmt; while ( pDb.stmtList != null ) { sqlite3_finalize( ref pDb.stmtList.pStmt ); pPreStmt = pDb.stmtList; pDb.stmtList = pDb.stmtList.pNext; TCL.Tcl_Free( ref pPreStmt ); } pDb.nStmt = 0; pDb.stmtLast = null; }
//#define closeIncrblobChannels(pDb) static void closeIncrblobChannels( SqliteDb pDb ) { }
public static void CreateReports(MySqlDb mySqlDatabase, SqliteDb sqliteDb, FileInfo fileInfo) { var allReports = mySqlDatabase.SalesRepository .All() .Select(x => x) .ToList(); var allShops = sqliteDb.Shops .GroupBy(x => new { x.Name, x.Town }) .ToList() .Select(x => x.FirstOrDefault()); using (var excelPackage = new ExcelPackage(fileInfo)) { foreach (var shop in allShops) { var worksheetName = $"{shop.Name} - {shop.Town}"; var isExisting = excelPackage.Workbook.Worksheets.Any(x => x.Name == worksheetName); if (isExisting) { excelPackage.Workbook.Worksheets.Delete(worksheetName); } ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add(worksheetName); worksheet.Cells["A1"].Value = "Employee"; worksheet.Cells["B1"].Value = "Product"; worksheet.Cells["C1"].Value = "Date"; worksheet.Cells["D1"].Value = "Revenue"; worksheet.Cells["A1,B1,C1,D1"].Style.Font.Bold = true; worksheet.Cells["A1,B1,C1,D1"].Style.Border.Bottom.Style = ExcelBorderStyle.Thin; worksheet.Column(1).Width = 15; worksheet.Column(2).Width = 15; worksheet.Column(3).Width = 10; int rowCounter = 2; var rowCounterAsString = rowCounter.ToString(); decimal totalRevenue = 0; var shopReports = allReports.Where(x => x.Shop == shop.Name).OrderBy(x => x.Date); foreach (var shopReport in shopReports) { var shopReportDate = shopReport.Date; worksheet.Cells["A" + rowCounterAsString].Value = shopReport.Employee; worksheet.Cells["B" + rowCounterAsString].Value = shopReport.Product; worksheet.Cells["C" + rowCounterAsString].Value = $"{shopReportDate.Day}/{shopReportDate.Month}/{shopReportDate.Year}"; worksheet.Cells["D" + rowCounterAsString].Value = shopReport.TotalValue; totalRevenue += shopReport.TotalValue; rowCounter++; rowCounterAsString = rowCounter.ToString(); } { var currRowCellA = "A" + rowCounterAsString; var currRowCellB = "B" + rowCounterAsString; var currRowCellC = "C" + rowCounterAsString; var currRowCellD = "D" + rowCounterAsString; worksheet.Cells[$"{currRowCellA}:{currRowCellB}"].Merge = true; worksheet.Cells[$"{currRowCellA}:{currRowCellB}"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; worksheet.Cells[$"{currRowCellA}:{currRowCellB}"].Value = "Total Revenue: "; worksheet.Cells[currRowCellD].Value = totalRevenue; worksheet.Cells[$"{currRowCellD}"].Style.Font.Bold = true; worksheet.Cells[$"{currRowCellA},{currRowCellB},{currRowCellC},{currRowCellD}"].Style.Border .Top.Style = ExcelBorderStyle.Thick; worksheet.Cells[$"{currRowCellA},{currRowCellB},{currRowCellC},{currRowCellD}"].Style.Border .Bottom.Style = ExcelBorderStyle.Thick; } } excelPackage.Save(); } }
//Loads the form public void LoadForm(SqliteDb newDatabase) { //Create a new virtual machine this.database = newDatabase; int status = Sqlite.Ok; this.vm = new SqliteVm(newDatabase, true); //Get all tests from the test case table and add the in the dropdown box status = this.vm.Execute("Select TestName from TestCase"); while (Sqlite.Row == status) { this.testNameList.Items.Add(this.vm.GetString("TestName")); status = this.vm.NextRow(); } //If we have any tests in the list select the first one by default if (this.testNameList.Items.Count > 0) { this.testNameList.SelectedIndex = 0; this.testName = this.testNameList.SelectedItem.ToString(); } }
public abstract int ValidateRequest(SqliteDb db, string testName, int paramSetId, string operation, TestResult actualResult, ITestLogger logger);
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; }
/* ** Close all incrblob channels opened using database connection pDb. ** This is called when shutting down the database connection. */ static void closeIncrblobChannels( SqliteDb pDb ) { IncrblobChannel p; IncrblobChannel pNext; for ( p = pDb.pIncrblob ; p != null ; p = pNext ) { pNext = p.pNext; /* Note: Calling unregister here call TCL.Tcl_Close on the incrblob channel, ** which deletes the IncrblobChannel structure at p. So do not ** call TCL.Tcl_Free() here. */ TCL.Tcl_UnregisterChannel( pDb.interp, p.channel ); } }
static int createIncrblobChannel( Tcl_Interp interp, SqliteDb pDb, string zDb, string zTable, string zColumn, sqlite_int64 iRow, int isReadonly ){ IncrblobChannel p; sqlite3 db = pDb.db; sqlite3_blob pBlob; int rc; int flags = TCL.Tcl_READABLE|(isReadonly ? 0 : TCL.Tcl_WRITABLE); /* This variable is used to name the channels: "incrblob_[incr count]" */ //static int count = 0; string zChannel = "";//string[64]; rc = sqlite3_blob_open(db, zDb, zTable, zColumn, iRow, !isReadonly, pBlob); if( rc!=SQLITE_OK ){ TCL.Tcl_SetResult(interp, sqlite3_errmsg(pDb.db), TCL.Tcl_VOLATILE); return TCL.TCL_ERROR; } p = new IncrblobChannel();//(IncrblobChannel *)Tcl_Alloc(sizeof(IncrblobChannel)); p.iSeek = 0; p.pBlob = pBlob; sqlite3_snprintf(64, zChannel, "incrblob_%d", ++count); p.channel = TCL.Tcl_CreateChannel(IncrblobChannelType, zChannel, p, flags); TCL.Tcl_RegisterChannel(interp, p.channel); /* Link the new channel into the SqliteDb.pIncrblob list. */ p.pNext = pDb.pIncrblob; p.pPrev = null; if( p.pNext!=null ){ p.pNext.pPrev = p; } pDb.pIncrblob = p; p.pDb = pDb; TCL.Tcl_SetResult(interp, Tcl_GetChannelName(p.channel), TCL.Tcl_VOLATILE); return TCL.TCL_OK; }
public static void Run(string[] args, ConfigFile configFile) { try { string dbname = (args.Length > 1) && (args[1] != null) ? args[1] : null; SqliteDb db = new SqliteDb(dbname, true, null, configFile.Extract.Delimiter, configFile.Db.LogFile).Init(); if (dbname == null) { dbname = "a transient in-memory database."; } Writer = new PlainTextResultWriter(Console.Out, Console.Out, Console.Out); var tables = db.GetTableNames(); var columns = new List <string>(); foreach (var t in tables) { foreach (var col in db.GetColumnNamesForTable(t)) { if (!columns.Contains(col)) { columns.Add(col); } } } var startupMsg = "ETLyte v. " + Globals.Version; startupMsg += Environment.NewLine + "Connected to " + dbname; string prompt = "ETLyte> "; CSharpEvaluator eval = new CSharpEvaluator(); InteractivePrompt.Run( ((cmd, rawinput, completions) => { // add new completions foreach (var c in cmd.Split(' ')) { if (!completions.Contains(c)) { completions.Add(c); } } string retstr = ""; var arg = cmd.Split(' '); var firstArg = arg[0]; if (firstArg.Trim()[0] == '.') { switch (firstArg.ToLower()) { case ".tables": var sqlcmd = "SELECT name FROM sqlite_master WHERE type='table';"; if (db.ExecuteQuery(sqlcmd, Writer) != 0) { Writer.WriteStd(db.LastError); } break; case ".output": if (arg[1].ToLower() == "json") { Writer = new JsonResultWriter(Console.Out, Console.Out, Console.Out); retstr = "Switched to JSON output" + Environment.NewLine; } else if (arg[1].ToLower() == "plain") { Writer = new PlainTextResultWriter(Console.Out, Console.Out, Console.Out); retstr = "Switched to plain output" + Environment.NewLine; } break; default: retstr = "Unrecognized command." + Environment.NewLine; break; } } else if (firstArg.Trim()[0] == '{') { retstr = eval.HandleCmd(cmd.Trim().Substring(1)) + Environment.NewLine; } else { if (db.ExecuteQuery(cmd, Writer) != 0) { Writer.WriteStd(db.LastError); } } return(retstr); }), prompt, startupMsg, tables.Concat(columns).ToList()); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.InnerException); Console.WriteLine(e.StackTrace); } }
/* ** Find an SqlFunc structure with the given name. Or create a new ** one if an existing one cannot be found. Return a pointer to the ** structure. */ static SqlFunc findSqlFunc( SqliteDb pDb, string zName ) { SqlFunc p, pNew; int i; pNew = new SqlFunc();//(SqlFunc)Tcl_Alloc( sizeof(*pNew) + strlen30(zName) + 1 ); //pNew.zName = (char*)&pNew[1]; //for(i=0; zName[i]; i++){ pNew.zName[i] = tolower(zName[i]); } //pNew.zName[i] = 0; pNew.zName = zName.ToLower(); for ( p = pDb.pFunc ; p != null ; p = p.pNext ) { if ( p.zName == pNew.zName ) { //Tcl_Free((char*)pNew); return p; } } pNew.interp = pDb.interp; pNew.pScript = null; pNew.pNext = pDb.pFunc; pDb.pFunc = pNew; return pNew; }
private void NewDatabase(bool template) { saveFileDialog1.Filter = "db files (*.db)|*.db|All files (*.*)|*.*"; saveFileDialog1.RestoreDirectory = true; SqliteDb db = null; string dbName = ""; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { dbName = saveFileDialog1.FileName; if (!IsReadOnly(dbName)) { //Close the existing database if (null != this.database) { this.CloseDatabase(); } //Delete the file this.DeleteFile(dbName); //Open the database. SQLite will create the file for us db = new SqliteDb(); db.Open(dbName); //Create a template database for the unit test infrastructure if (template && (db != null)) { SqliteVm templateVm = new SqliteVm(db, true); templateVm.Execute("CREATE TABLE TestCase (ExecuteSequence INTEGER, TestName TEXT, ParamSets TEXT, Description TEXT, TestType TEXT, Prerequisite TEXT)"); templateVm.Execute("CREATE TABLE Params (ParamSet INTEGER, ParamName TEXT, ParamValue TEXT)"); templateVm.Execute("CREATE TABLE CommonParams (ParamName text, ParamValue text)"); templateVm.Execute("CREATE TABLE ApiTestResults (Description TEXT, ParamSet INTEGER, ContentType TEXT, Result TEXT)"); templateVm.Execute("CREATE TABLE HttpTestResults (Description TEXT, ParamSet INTEGER, ContentType TEXT, Result BLOB)"); templateVm.SqlFinalize(); templateVm = null; } db.Close(); //Open the new database this.OpenDatabase(dbName); } else { string errMsg; errMsg = String.Format("File {0} is readOnly and cannot be replaced", dbName); System.Windows.Forms.MessageBox.Show(errMsg, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand); this.NewDatabase(template); } } }
//Implements SaveAs functionality private void SaveAs() { saveFileDialog1.Filter = "db files (*.db)|*.db|All files (*.*)|*.*"; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { string newName = saveFileDialog1.FileName; //Should never be hit if (null == database) { System.Windows.Forms.MessageBox.Show("No database is open", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand, System.Windows.Forms.MessageBoxDefaultButton.Button1); } else if (IsReadOnly(newName)) { string errMsg = String.Format("File {0} is read only! \nSave the file under different name?", newName); DialogResult result = System.Windows.Forms.MessageBox.Show(errMsg, "Error", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Hand, System.Windows.Forms.MessageBoxDefaultButton.Button1); if (DialogResult.Yes == result) { this.SaveAs(); } } else { //If the source file is read only the CopyTo method will also create a ReadOnly file //Take the new file and remove the ReadOnly attribute in order to be able to save any new changes System.IO.FileAttributes attribute = new System.IO.FileAttributes(); FileInfo oldDbFile = new FileInfo(database.GetName()); oldDbFile.CopyTo(newName, true); if (IsReadOnly(database.GetName())) { FileInfo newDbFile = new FileInfo(newName); newDbFile.Attributes = FileAttributes.Archive; } //Open the new file database.Close(); database = new SqliteDb(); database.Open(newName); this.SaveDatabase(); this.OpenDatabase(newName); } } }
private void CloseDatabase() { if (database != null) { //If the file is not read only save the data first else close all forms if (!IsReadOnly(database.GetName())) { this.SaveDatabase(); } else { this.CloseForms(); } database.Close(); database = null; treeView1.BeginUpdate(); treeView1.Nodes.Clear(); treeView1.EndUpdate(); } //Disable menu items this.menuItem3.Enabled = false; this.menuAddTest.Enabled = false; this.saveAsMenuItem.Enabled = false; this.saveDbMenuItem.Enabled = false; }
public void DeleteCauseChain(Node node) { ExecuteCommand(new RemoveNodeChainCommand(SqliteDb.GetInstance(), node)); }
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; }
static void Main(string[] args) { // Choose the data mining operation from input Console.WriteLine("Input BC for binary classification, MC for multiclass classification, or C for clustering"); var userInput = Console.ReadLine(); if (userInput == "BC") { Console.WriteLine("BC selected"); // Connect to the binary classification DB var path = Path.GetFullPath("./binaryclassification.db"); var db = new SqliteDb(path); db.Connect(); // Setup a tokenizer, parser, and SQL converter var handler = new FUSQLHandler(); var query = handler.ParseQuery("CHECK 'PRETTY GOOD!' FROM imdblabelled\n"); var translation = Translator.TranslateQuery <Text>(query); var result = translation.RunBinaryClassification(db); Console.WriteLine($"Sentiment: {translation.Operation.Text} | Prediction: {(Convert.ToBoolean(result.Prediction) ? "Positive" : "Negative")} | Probability: {result.Probability} "); Console.ReadLine(); } else if (userInput == "MC") { Console.WriteLine("MC selected"); // Connect to the multiclass classification DB var path = Path.GetFullPath("./multiclass.db"); var db = new SqliteDb(path); db.Connect(); // Setup a tokenizer, parser, and SQL converter var handler = new FUSQLHandler(); var query = handler.ParseQuery("IDENTIFY '404 error not found' 'Cant find webpage!' FROM issuestrain\n"); var translation = Translator.TranslateQuery <IssueDesc>(query); var result = translation.RunMulticlassClassification(db); //var resultView = new MulticlassClassification(); //resultView.BuildModel(); //MulticlassClassificationData issue = new MulticlassClassificationData() //{ // Title = "WebSockets communication is slow in my machine", // Description = "The WebSockets communication used under the covers by SignalR looks like is going slow in my development machine.." //}; Console.WriteLine($"=============== Single Prediction just-trained-model - Result: {result.Area} ==============="); Console.ReadLine(); } else if (userInput == "C") { Console.WriteLine("C selected"); // Connect to the database var path = Path.GetFullPath("./database.sqlite"); var db = new SqliteDb(path); db.Connect(); // Setup a tokenizer, parser, and SQL converter var handler = new FUSQLHandler(); var query = handler.ParseQuery("FIND 5 GROUPS irisClusters USING SepalLengthCm PetalLengthCm FROM Iris\n"); var translation = Translator.TranslateQuery <Iris>(query); var resultView = translation.RunClustering(db); // Perform a data mining query operation // dbSQLite(); foreach (var key in (resultView as ClusterResultView <Iris>).Clusters.Keys) { Console.WriteLine("Cluster " + key + " count : " + (resultView as ClusterResultView <Iris>).Clusters[key].Count); } Console.ReadLine(); } else { Console.WriteLine("\nInvalid input."); } }
public static int Run(ConfigFile c, string cmd = "", string filename = "") { configFile = c; if (!String.IsNullOrWhiteSpace(cmd)) { try { Validate = new PlainTextResultWriter(Console.Out, Console.Out, Console.Out, Console.Out, configFile.Validate.Outputs.StandardOutputDelimiter); string sql = cmd; db = new SqliteDb(configFile.Db.DbName, true, null, configFile.Extract.Delimiter, configFile.Db.LogFile).Init(); SqliteStatus = db.ExecuteQuery(sql, Validate, "Command line query"); } catch (Exception e) { Console.WriteLine("Something went wrong trying to read the input command. Try again... " + e.Message); } } else if (!String.IsNullOrWhiteSpace(filename)) { try { Validate = new PlainTextResultWriter(Console.Out, Console.Out, Console.Out, Console.Out, configFile.Validate.Outputs.StandardOutputDelimiter); string sql = GetSqlContents(filename); db = new SqliteDb(configFile.Db.DbName, true, null, configFile.Extract.Delimiter, configFile.Db.LogFile).Init(); SqliteStatus = db.ExecuteQuery(sql, Validate, "Command line file execution"); } catch (Exception e) { Console.WriteLine("Something went wrong trying to read the input file. Try again... " + e.Message); } } else { try { Validate = new PlainTextResultWriter(Console.Out, Console.Out, Console.Out, Console.Out); Transform = new PlainTextResultWriter(Console.Out, Console.Out, Console.Out, Console.Out); Load = new PlainTextResultWriter(Console.Out, Console.Out, Console.Out, Console.Out); Validations validator = null; SqliteStatus = 0; string sql; db = new SqliteDb(configFile.Db.DbName, configFile.Db.UseExistingDb, null, configFile.Extract.Delimiter, configFile.Db.LogFile).Init(); // NPS_TODO add error outputting for when these fail to load if (configFile.Steps.Validate) { Validate = ConfigFileInit.InitValidateFromConfig(configFile); } if (configFile.Steps.Transform) { Transform = ConfigFileInit.InitTransformFromConfig(configFile); } if (configFile.Steps.Load) { Load = ConfigFileInit.InitLoadFromConfig(configFile, db); } DirectoryInfo schemaDirInfo = new DirectoryInfo(configFile.Extract.Schemas); DirectoryInfo sourceFilesDirInfo = new DirectoryInfo(configFile.Extract.Source); DirectoryInfo validationDirInfo = new DirectoryInfo(configFile.Validate.ValidationSource); DirectoryInfo loadDirInfo = new DirectoryInfo(configFile.Load.LoadSource); DirectoryInfo seedDirInfo = new DirectoryInfo(configFile.Extract.SeedData); SchemaFile schemaFile = null; SqliteModeler modeler = null; Validate.BeginOutput(""); if (configFile.Steps.Extract) { //NPS_TODO: Add check to see if we need to do this on reuse db sql = new SqliteModeler().CreateGeneralErrorWarningDdl(); SqliteStatus = db.ModifyDdlFromSqlString(sql); Validate.WriteVerbose(SqliteStatus.ToString() + ":" + sql + "||" + db.LastError); // load seed data if (seedDirInfo.Exists) { foreach (var seedFile in seedDirInfo.GetFiles("*.sql")) { //NPS_TODO: Add check to see if we need to do this on reuse db currentStep = SetCurrentStep("Reading seed data from " + seedFile.Name, Validate); SqliteStatus = db.ExecuteQuery(File.ReadAllText(seedFile.FullName), Validate); } } } foreach (var file in schemaDirInfo.GetFiles("*.json")) { //NPS_TODO: See if Scheme has already been created // create schemafile object currentStep = SetCurrentStep("Reading schema file: " + file.Name, Validate); schemaFile = JsonConvert.DeserializeObject <SchemaFile>(File.ReadAllText(file.FullName)); Validate.BeginContext(schemaFile.Name, Globals.ResultWriterDestination.stdOut); if (configFile.Validate.Outputs.Warnings && (configFile.Validate.Outputs.StandardOutputConnectionString != configFile.Validate.Outputs.WarningsOutputConnectionString)) { if (Validate.ResultMode == "delimited") { Validate.Write(schemaFile.Name, Globals.ResultWriterDestination.Warning); } else if (Validate.ResultMode == "json") { Validate.BeginContext(schemaFile.Name, Globals.ResultWriterDestination.Warning); } } // create SQLiteModeler currentStep = SetCurrentStep("Setting schema file: " + file.Name, Validate); modeler = new SqliteModeler().SetSchemaFile(schemaFile); // create SQL from schemafile currentStep = SetCurrentStep("Creating DDL...", Validate); sql = modeler.CreateDdl(true).Ddl; // execute DDL in schemafile currentStep = SetCurrentStep("Modifying SQLite DB with DDL...", Validate); SqliteStatus = db.ModifyDdlFromSqlString(sql); Validate.WriteVerbose(SqliteStatus.ToString() + ":" + sql); // create SQL from schemafile currentStep = SetCurrentStep("Creating DDL...", Validate); sql = modeler.CreateErrorDdl().ErrorDdl; // execute DDL in schemafile currentStep = SetCurrentStep("Modifying SQLite DB with Error DDL...", Validate); SqliteStatus = db.ModifyDdlFromSqlString(sql); Validate.WriteVerbose(SqliteStatus.ToString() + ":" + sql); // find linked flat file var files = GetFullFilePath(sourceFilesDirInfo, schemaFile.Flatfile, Validate); Flatfile flatfile = null; if (configFile.Steps.Extract) { foreach (var f in files) { var reuseDbSql = "SELECT * FROM FileAudit WHERE FileName = '" + f + "';"; bool shouldReadFile = true; if (configFile.Db.UseExistingDb && db.QueryHasResults(reuseDbSql)) { shouldReadFile = false; } if (f != String.Empty && shouldReadFile) { //import flat file currentStep = SetCurrentStep("Importing flatfile " + f + "...", Validate); //NPS_TODO: setup File flatfile = new Flatfile(f, schemaFile.Name, schemaFile.Delimiter.ToString(), "\"", true, null, schemaFile); int linesRead = 0; SqliteStatus = db.ImportDelimitedFile(flatfile, out linesRead, configFile, true); // NPS_TODO: Make linenum optional in configfile currentStep = SetCurrentStep("Finished reading flatfile " + f + "...", Validate); var auditSql = "INSERT INTO FileAudit VALUES ('" + f + "', CURRENT_TIMESTAMP, " + schemaFile.Fields.Count + ", " + linesRead + ");"; SqliteStatus = db.ExecuteQuery(auditSql, Validate); } } if (files.Count == 0) { SqliteStatus = db.ExecuteQuery("INSERT INTO GeneralErrors VALUES ('File Missing', 'None', '" + schemaFile.Name + "', 'Error', 'Failed to find file matching " + schemaFile.Flatfile + "');", Validate); Validate.EndContext(Globals.ResultWriterDestination.stdOut); continue; // no files, continue the loop so no validation happens } else { var metadataSql = ""; // NPS_TODO: Handle Derivations flag // DERIVATIONS foreach (var schemaField in flatfile.Schemafile.Fields.Where(x => x.ColumnType == ColumnType.Derived).Select(x => x)) { var derivationSql = "UPDATE " + flatfile.Tablename + " SET " + schemaField.Name + " = " + schemaField.Derivation + ";"; SqliteStatus = db.ExecuteQuery(derivationSql, Validate); } foreach (var schemaField in schemaFile.Fields) { metadataSql = "INSERT INTO TableMetadata VALUES ('" + schemaFile.Name + "', '" + schemaField.Name + "', '" + schemaField.DataType + "');"; // finding numeric precision/scale for sql server // with cte as (select length(b)-1 as precision, length(b) - instr(b, '.') as scale from foo) select case when // max(precision) - min(scale) >= 38 then 38 else max(precision) end as precision, max(scale) from cte; SqliteStatus = db.ExecuteQuery(metadataSql, Validate); } metadataSql = "INSERT INTO TableMetadata VALUES ('" + schemaFile.Name + "', 'LineNum', 'int');"; SqliteStatus = db.ExecuteQuery(metadataSql, Validate); } } #region Validate // file level validations if (configFile.Steps.Validate) { validator = new Validations(configFile.Validate.SchemaErrorSettings, db, Validate, (code => SqliteStatus = code), configFile.Validate, schemaFile.Name); currentStep = SetCurrentStep("Validating file", Validate); foreach (var schemaField in schemaFile.Fields) { validator.ValidateFields(schemaField, schemaFile.Name, Validate); } if (schemaFile.SummarizeResults) { validator.PrintSummaryResults(schemaFile.Name, Globals.ResultWriterDestination.stdOut); if (configFile.Validate.Outputs.Warnings) { validator.PrintSummaryResults(schemaFile.Name, Globals.ResultWriterDestination.Warning); } } validator.PrintDetailResults(schemaFile.Name, Globals.ResultWriterDestination.stdOut); if (configFile.Validate.Outputs.Warnings) { validator.PrintDetailResults(schemaFile.Name, Globals.ResultWriterDestination.Warning); } } Validate.EndContext(Globals.ResultWriterDestination.stdOut); if (Validate.ResultMode == "json" && configFile.Validate.Outputs.Warnings && (configFile.Validate.Outputs.StandardOutputConnectionString != configFile.Validate.Outputs.WarningsOutputConnectionString)) { Validate.EndContext(Globals.ResultWriterDestination.Warning); } } // end for each flat file // // Custom validation checks // Possibly cross file / multi table joins // if (configFile.Steps.Validate && !string.IsNullOrWhiteSpace(configFile.Validate.ValidationSource)) { string ctx = "Custom Data Validation Checks"; // Perhaps we have no flatfiles but do have a db and custom validations - in this case validator would be null if (validator == null) { validator = new Validations(configFile.Validate.SchemaErrorSettings, db, Validate, (code => SqliteStatus = code), configFile.Validate, "GeneralErrors"); } Validate.BeginContext(ctx, Globals.ResultWriterDestination.stdOut); if (configFile.Validate.Outputs.Warnings && (configFile.Validate.Outputs.StandardOutputConnectionString != configFile.Validate.Outputs.WarningsOutputConnectionString)) { if (Validate.ResultMode == "delimited") { Validate.Write(ctx, Globals.ResultWriterDestination.Warning); } else if (Validate.ResultMode == "json") { Validate.BeginContext(ctx, Globals.ResultWriterDestination.Warning); } } foreach (var validationFile in validationDirInfo.GetFiles("*.sql")) { currentStep = SetCurrentStep("Getting contents from: " + validationFile.Name, Validate); validator.ValidateCustom(validationFile, configFile.Validate.QueryErrorLimit, configFile.Validate.Outputs.Warnings); } Validate.EndContext(Globals.ResultWriterDestination.stdOut); if (Validate.ResultMode == "json" && configFile.Validate.Outputs.Warnings && (configFile.Validate.Outputs.StandardOutputConnectionString != configFile.Validate.Outputs.WarningsOutputConnectionString)) { Validate.EndContext(Globals.ResultWriterDestination.Warning); } } if (configFile.Steps.Validate) { validator.PrintGeneralIssues(Globals.ResultWriterDestination.stdOut); if (configFile.Validate.Outputs.Warnings) { validator.PrintGeneralIssues(Globals.ResultWriterDestination.Warning); } } Validate.EndOutput(""); #endregion Validate Load.BeginOutput(""); if (configFile.Steps.Load) { foreach (var loadFile in loadDirInfo.GetFiles("*.sql")) { currentStep = SetCurrentStep("Getting contents from: " + loadFile.Name, Validate); string context = String.Empty; sql = GetSqlContents(loadFile.FullName); context = loadFile.Name; SqliteStatus = db.ExecuteQuery(sql, Load, context); } } } catch (Exception e) { Validate.WriteStd("ERROR on step: " + currentStep); Validate.WriteError("[ERROR] " + DateTime.Now); Validate.WriteError("[ERROR MSG] " + e.Message); if (db != null && !string.IsNullOrWhiteSpace(db.LastError)) { Validate.WriteError("[DB MSG] " + db.LastError); } Validate.WriteError(e.StackTrace); return(SqliteStatus); } finally { db.Close(); Validate.Dispose(); } } return(SqliteStatus); }
public Tcl_Obj[] apColName; /* Array of column names */ public void Clear() { pDb = null; pSql = null; zSql = null; pPreStmt = null; pArray = null; apColName = null; }
//Create a FileInfo object and overwrite the ReadOnly attribute //Create a new SqliteDb object as the old will not be aware of the change //Send the new object to the parent form private void MakeWriteable(string dbName) { FileInfo dbFile = new FileInfo(dbName); dbFile.Attributes = FileAttributes.Archive; if (null != this.vm) { this.vm.SqlFinalize(); } this.database.Close(); this.database = new SqliteDb(); this.database.Open(dbName); Form1 form = this.ParentForm as Form1; if (form != null) { form.SetDatabase(database); } this.vm = new SqliteVm(this.database, true); }
public void CreateChildNode(string text, Node parent) { ExecuteCommand(new AddNodeCommand(SqliteDb.GetInstance(), parent, text)); }