public void LoadColumns(SqlDataConnection connection, params DBTable[] tables) { foreach (DBTable table in tables) { if (table.Name == "Categories" && table.Columns.Count == 0) { DBColumn categoryIdColumn = new DBColumn { Name = "CategoryID", ColumnType = DBColumnType.Int32 }; table.AddColumn(categoryIdColumn); DBColumn categoryNameColumn = new DBColumn { Name = "CategoryName", ColumnType = DBColumnType.String }; table.AddColumn(categoryNameColumn); } if (table.Name == "Products" && table.Columns.Count == 0) { DBColumn categoryIdColumn = new DBColumn { Name = "CategoryID", ColumnType = DBColumnType.Int32 }; table.AddColumn(categoryIdColumn); DBColumn productNameColumn = new DBColumn { Name = "ProductName", ColumnType = DBColumnType.String }; table.AddColumn(productNameColumn); DBForeignKey foreignKey = new DBForeignKey( new[] { categoryIdColumn }, "Categories", CustomDBSchemaProvider.CreatePrimaryKeys("CategoryID")); table.ForeignKeys.Add(foreignKey); } } }
IEnumerable <DevExpress.DataAccess.Sql.SqlDataConnection> IConnectionStorageService.GetConnections() { if (!File.Exists(FileName)) { try { //Create empty XML file XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement(xmlRootName); doc.AppendChild(root); doc.Save(FileName); //Add a connection to the XML file: SqlDataConnection defaultConnection = GetConnection(); //GetConnectionsFromXml(); // new CustomSqlDataConnection("Default Connection", new MsSqlConnectionParameters("localhost", "NORTHWIND", "sa", "dx", MsSqlAuthorizationType.SqlServer)); SaveConnection(defaultConnection.Name, defaultConnection, true); } catch (Exception ex) { MessageBox.Show(string.Format("Cannot create '{0}' file because of exception:{1}{1}{2}", FileName, Environment.NewLine, ex.Message)); return(null); } } return(IncludeApplicationConnections ? DefaultStorage.GetConnections().Union(GetConnectionsFromXml()) : GetConnectionsFromXml()); }
public DBTable[] GetTables(SqlDataConnection connection, params string[] tableList) { // Check permissions var dbTables = connection.GetDBSchema().Tables; return(dbTables.Where(t => t.Name == "Categories" || t.Name == "Products").ToArray()); }
public void TestNew() { Filename = Path.GetTempFileName(); File.Delete(Filename); SqlDataConnection.New(Filename); Assert.IsTrue(SqlDataConnection.IsOpen()); }
public void TestOpen_InvalidFile() { Filename = Path.GetTempFileName(); Assert.Throws <FileLoadException>(new TestDelegate( delegate { SqlDataConnection.Open(Filename); })); }
public void LoadColumns(SqlDataConnection connection, params DBTable[] tables) { foreach (DBTable table in tables) { if (table.Name == "Categories" && table.Columns.Count == 0) { DBColumn categoryIdColumn = new DBColumn { Name = "CategoryID" }; table.AddColumn(categoryIdColumn); DBColumn categoryNameColumn = new DBColumn { Name = "CategoryName" }; table.AddColumn(categoryNameColumn); } if (table.Name == "Products" && table.Columns.Count == 0) { DBColumn categoryIdColumn = new DBColumn { Name = "CategoryID" }; table.AddColumn(categoryIdColumn); DBColumn supplierIdColumn = new DBColumn { Name = "SupplierID" }; table.AddColumn(supplierIdColumn); DBColumn productNameColumn = new DBColumn { Name = "ProductName" }; table.AddColumn(productNameColumn); DBForeignKey foreignKey1 = new DBForeignKey( new[] { categoryIdColumn }, "Categories", CustomDBSchemaProvider.CreatePrimaryKeys("CategoryID")); table.ForeignKeys.Add(foreignKey1); DBForeignKey foreignKey2 = new DBForeignKey( new[] { supplierIdColumn }, "Suppliers", CustomDBSchemaProvider.CreatePrimaryKeys("SupplierID")); table.ForeignKeys.Add(foreignKey2); } if (table.Name == "Suppliers" && table.Columns.Count == 0) { DBColumn supplierIdColumn = new DBColumn { Name = "SupplierID" }; table.AddColumn(supplierIdColumn); DBColumn companyNameColumn = new DBColumn { Name = "CompanyName" }; table.AddColumn(companyNameColumn); } } }
public DBSchema GetSchema(SqlDataConnection connection) { //Load DB Schema without loading columns DBSchema defaultSchema = connection.GetDBSchema(false); //Select only required tables/views/procedures DBTable[] tables = defaultSchema.Tables.Where((table) => { return(!table.Name.StartsWith("Order")); }).ToArray(); DBTable[] views = defaultSchema.Views.ToArray(); DBStoredProcedure[] storedProcedures = defaultSchema.StoredProcedures.ToArray(); //Create a new schema return(new DBSchema(tables, views, storedProcedures)); }
public bool SaveConnection(SqlDataConnection connection) { try { XmlDocument doc = new XmlDocument(); XmlElement root = null; if (File.Exists(FileName)) { doc.Load(FileName); root = doc.DocumentElement; if (root != null) { if (root.Name != xmlRootName) { MessageBox.Show(string.Format("Document element is '{0}', '{1}' expected", root.Name, xmlRootName)); return(false); } if (root.SelectSingleNode(string.Format("Connection[Name = '{0}']", connection.Name)) != null) { return(false); } } } if (root == null) { root = doc.CreateElement(xmlRootName); doc.AppendChild(root); } XmlElement nameElement = doc.CreateElement("Name"); nameElement.AppendChild(doc.CreateTextNode(connection.Name)); XmlElement connectionStringElement = doc.CreateElement("ConnectionString"); connectionStringElement.AppendChild(doc.CreateTextNode(connection.CreateConnectionString())); XmlElement connectionElement = doc.CreateElement("Connection"); connectionElement.AppendChild(nameElement); connectionElement.AppendChild(connectionStringElement); root.AppendChild(connectionElement); doc.Save(FileName); return(true); } catch (Exception ex) { MessageBox.Show(string.Format("Cannot save connection to '{0}' because of exception:{1}{1}{2}", FileName, Environment.NewLine, ex.Message)); return(false); } }
public void TestBackup() { Filename = Path.GetTempFileName(); File.Delete(Filename); SqlDataConnection.New(Filename); string backup = Path.GetTempFileName(); Assert.IsTrue(SqlDataConnection.Backup(backup)); SqlDataConnection.Close(); Assert.IsFalse(SqlDataConnection.Backup(backup)); File.Delete(backup); }
public void TestFlush() { Filename = Path.GetTempFileName(); File.Delete(Filename); SqlDataConnection.New(Filename); SqlDataConnection.Flush(); SqlDataConnection.Flush(true); SqlDataConnection.Flush(false); SqlDataConnection.DbConnection.Close(); SqlDataConnection.Flush(); SqlDataConnection.Flush(true); SqlDataConnection.Flush(false); }
public override DBTable[] GetTables(SqlDataConnection connection, params string[] tableList) { var result = base.GetTables(connection, tableList); var userName = contextAccessor.HttpContext.Session.GetString("CurrentUser"); if (userName == "Admin") { return(result); } else if (userName == "User") { return(result.Where(t => t.Name == "Cars").ToArray()); } else { return(new DBTable[0]); } }
public void TestNew_FileExists() { Filename = Path.GetTempFileName(); Assert.Throws <FileLoadException>(new TestDelegate( delegate { SqlDataConnection.New(Filename); })); File.Delete(Filename); SqlDataConnection.New(Filename); Assert.Throws <InvalidOperationException>(new TestDelegate( delegate { SqlDataConnection.New(Filename); })); }
protected override void CleanupImpl() { if (SqlDataConnection != null) { if (SqlDataConnection.IsOpen()) { SqlDataConnection.Close(); } SqlDataConnection.Dispose(); } SqlDataConnection = null; if (!string.IsNullOrEmpty(Filename) && File.Exists(Filename)) { File.Delete(Filename); } }
public DBTable[] GetTables(SqlDataConnection connection, params string[] tableList) { var cp = connection.ConnectionParameters as Access97ConnectionParameters; if (cp != null && cp.FileName.Contains("nwind.mdb")) { if (tables != null) { return(tables); } tables = new DBTable[3]; tables[0] = new DBTable("Categories"); tables[1] = new DBTable("Products"); tables[2] = new DBTable("Suppliers"); } else { tables = new DBTable[0]; } return(tables); }
public DBTable[] GetTables(SqlDataConnection connection, params string[] tableList) { if (connection.Name == "nwindConnection") { if (tables != null) { return(tables); } tables = new DBTable[2]; DBTable categoriesTable = new DBTable("Categories"); tables[0] = categoriesTable; DBTable productsTable = new DBTable("Products"); tables[1] = productsTable; } else { tables = new DBTable[0]; } return(tables); }
/// <summary> /// Performs the initial tasks before executing a query. /// </summary> /// <param name="oCmd">Command object holding the query.</param> private void InitQuery(SqlCommand oCmd) { // set Connection blnLocalConn = (this.oConn == null); if (blnLocalConn) { oConn = new SqlDataConnection(); blnLocalConn = true; oConn.Open(); } oCmd.Connection = oConn.oConn; // set Command oCmd.CommandTimeout = 0; oCmd.CommandText = this.strCommandText; oCmd.CommandType = (this.blnSP ? CommandType.StoredProcedure : CommandType.Text); // set Parameters foreach (object oItem in this.oParameters) { //System.Diagnostics.Debug.Print(oItem.ToString() +" : "+ ((SqlParameter)oItem).Value); oCmd.Parameters.Add((SqlParameter)oItem); } }
public DbContext(SqlDataConnection connection, ILoggerFactory loggerFactory) { _connection = connection; _loggerFactory = loggerFactory; }
public void LoadColumns(SqlDataConnection connection, params DBTable[] tables) { provider.LoadColumns(connection, tables); }
public void Test_FlushWneClosed() { SqlDataConnection.Flush(); SqlDataConnection.Flush(true); SqlDataConnection.Flush(false); }
public DBTable[] GetViews(SqlDataConnection connection, params string[] viewList) { return(provider.GetViews(connection, viewList) .ToArray()); }
public DBStoredProcedure[] GetProcedures(SqlDataConnection connection, params string[] procedureList) { return(provider.GetProcedures(connection, procedureList) .Where(storedProcedure => storedProcedure.Arguments.Count == 0) .ToArray()); }
public void LoadColumns(SqlDataConnection connection, params DBTable[] tables) { //Load columns for current tables connection.LoadDBColumns(tables); }
public DBTable[] GetTables(SqlDataConnection connection, params string[] tableList) { return(provider.GetTables(connection, tableList) .ToArray()); }
public void LoadColumns(SqlDataConnection connection, params DBTable[] tables) { }
QueryBuilderRunner CreateQueryBuilderRunner(DBSchema dbSchema, SqlDataConnection sqlDataConnection, QueryBuilderEditQueryContext context) { return(cbHidePreview.Checked ? new NoPreviewQueryBuilderRunner(dbSchema, sqlDataConnection, context) : new QueryBuilderRunner(dbSchema, sqlDataConnection, context)); }
public DBStoredProcedure[] GetProcedures(SqlDataConnection connection, params string[] procedureList) { return(Array.Empty <DBStoredProcedure>()); }
public DBTable[] GetViews(SqlDataConnection connection, params string[] viewList) { return(Array.Empty <DBTable>()); }
public DBTable[] GetTables(SqlDataConnection connection, params string[] tableList) { return(provider.GetTables(connection, tableList) .Where(table => table.Name.Equals("_PersonaJuridica")) .ToArray()); }
public DBTable[] GetViews(SqlDataConnection connection, params string[] viewList) { DBTable[] views = new DBTable[0]; return(views); }
public DBStoredProcedure[] GetProcedures(SqlDataConnection connection, params string[] procedureList) { DBStoredProcedure[] storedProcedures = new DBStoredProcedure[0]; return(storedProcedures); }