public void CatalogLocationTest () { OdbcCommandBuilder cb = new OdbcCommandBuilder (); Assert.AreEqual (CatalogLocation.Start, cb.CatalogLocation, "#1"); cb.CatalogLocation = CatalogLocation.End; Assert.AreEqual (CatalogLocation.End, cb.CatalogLocation, "#2"); }
public void GetInsertCommandTest () { OdbcConnection conn = (OdbcConnection) ConnectionManager.Singleton.Connection; OdbcCommand cmd = null; try { string selectQuery = "select id, lname from employee where id = 3"; OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn); DataSet ds = new DataSet (); da.Fill (ds, "IntTest"); Assert.AreEqual (1, ds.Tables.Count); OdbcCommandBuilder cb; cb = new OdbcCommandBuilder (da); cmd = cb.GetInsertCommand (); Assert.AreEqual ("INSERT INTO employee (id, lname) VALUES (?, ?)", cmd.CommandText, "#A1"); Assert.AreSame (conn, cmd.Connection, "#A2"); AssertInsertParameters (cmd, "#A3:"); cb = new OdbcCommandBuilder (da); cb.QuotePrefix = "\""; cmd = cb.GetInsertCommand (); Assert.AreEqual ("INSERT INTO \"employee (\"id, \"lname) VALUES (?, ?)", cmd.CommandText, "#B1"); Assert.AreSame (conn, cmd.Connection, "#B2"); AssertInsertParameters (cmd, "#B3:"); cb = new OdbcCommandBuilder (da); cb.QuoteSuffix = "´"; cmd = cb.GetInsertCommand (); Assert.AreEqual ("INSERT INTO employee´ (id´, lname´) VALUES (?, ?)", cmd.CommandText, "#C1"); Assert.AreSame (conn, cmd.Connection, "#C2"); AssertInsertParameters (cmd, "#C3:"); cb = new OdbcCommandBuilder (da); cb.QuotePrefix = "\""; cb.QuoteSuffix = "´"; cmd = cb.GetInsertCommand (); Assert.AreEqual ("INSERT INTO \"employee´ (\"id´, \"lname´) VALUES (?, ?)", cmd.CommandText, "#D1"); Assert.AreSame (conn, cmd.Connection, "#D2"); AssertInsertParameters (cmd, "#D3:"); } finally { if (cmd != null) cmd.Dispose (); ConnectionManager.Singleton.CloseConnection (); } }
public void CatalogSeparator () { OdbcCommandBuilder cb = new OdbcCommandBuilder (); Assert.AreEqual (".", cb.CatalogSeparator, "#1"); cb.CatalogSeparator = "a"; Assert.AreEqual ("a", cb.CatalogSeparator, "#2"); cb.CatalogSeparator = null; Assert.AreEqual (".", cb.CatalogSeparator, "#3"); cb.CatalogSeparator = "b"; Assert.AreEqual ("b", cb.CatalogSeparator, "#4"); cb.CatalogSeparator = string.Empty; Assert.AreEqual (".", cb.CatalogSeparator, "#5"); cb.CatalogSeparator = " "; Assert.AreEqual (" ", cb.CatalogSeparator, "#6"); }
public void CatalogLocation_Value_Invalid () { OdbcCommandBuilder cb = new OdbcCommandBuilder (); cb.CatalogLocation = CatalogLocation.End; try { cb.CatalogLocation = (CatalogLocation) 666; Assert.Fail ("#1"); } catch (ArgumentOutOfRangeException ex) { // The CatalogLocation enumeration value, 666, is invalid Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); Assert.IsTrue (ex.Message.IndexOf ("CatalogLocation") != -1, "#5:" + ex.Message); Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6:" + ex.Message); } Assert.AreEqual (CatalogLocation.End, cb.CatalogLocation, "#6"); }
[Test] // QuoteIdentifier (String) public void QuoteIdentifier1 () { OdbcCommandBuilder cb; cb = new OdbcCommandBuilder (); cb.QuotePrefix = "aBc"; Assert.AreEqual ("aBcmoAbCno", cb.QuoteIdentifier ("moAbCno"), "#A1"); Assert.AreEqual ("aBc", cb.QuoteIdentifier (string.Empty), "#A2"); Assert.AreEqual ("aBcZ", cb.QuoteIdentifier ("Z"), "#A3"); Assert.AreEqual ("aBcabc", cb.QuoteIdentifier ("abc"), "#A4"); cb.QuoteSuffix = "deF"; Assert.AreEqual ("aBcmodEfnodeF", cb.QuoteIdentifier ("modEfno"), "#A5"); Assert.AreEqual ("aBcdeF", cb.QuoteIdentifier (string.Empty), "#A6"); Assert.AreEqual ("aBcZdeF", cb.QuoteIdentifier ("Z"), "#A7"); Assert.AreEqual ("aBcabcdeF", cb.QuoteIdentifier ("abc"), "#A8"); cb = new OdbcCommandBuilder (); cb.QuotePrefix = "X"; Assert.AreEqual ("XmoXno", cb.QuoteIdentifier ("moXno"), "#B1"); Assert.AreEqual ("X", cb.QuoteIdentifier (string.Empty), "#B2"); Assert.AreEqual ("XZ", cb.QuoteIdentifier ("Z"), "#B3"); Assert.AreEqual ("XX", cb.QuoteIdentifier ("X"), "#B4"); cb.QuoteSuffix = " "; Assert.AreEqual ("Xmo no ", cb.QuoteIdentifier ("mo no"), "#B5"); Assert.AreEqual ("X ", cb.QuoteIdentifier (string.Empty), "#B6"); Assert.AreEqual ("XZ ", cb.QuoteIdentifier ("Z"), "#B7"); Assert.AreEqual ("X ", cb.QuoteIdentifier (" "), "#B8"); cb = new OdbcCommandBuilder (); cb.QuotePrefix = " "; Assert.AreEqual ("mono", cb.QuoteIdentifier ("mono"), "#C1"); Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty), "#C2"); Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z"), "#C3"); cb.QuoteSuffix = "dEf"; Assert.AreEqual ("modefno", cb.QuoteIdentifier ("modefno"), "#C4"); Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty), "#C5"); Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z"), "#C6"); cb = new OdbcCommandBuilder (); cb.QuotePrefix = " "; Assert.AreEqual (" mono", cb.QuoteIdentifier ("mono"), "#D1"); Assert.AreEqual (" ", cb.QuoteIdentifier (string.Empty), "#D2"); Assert.AreEqual (" Z", cb.QuoteIdentifier ("Z"), "#D3"); cb.QuoteSuffix = "dEf"; Assert.AreEqual (" moDeFnodEf", cb.QuoteIdentifier ("moDeFno"), "#D4"); Assert.AreEqual (" modEfdEfnodEf", cb.QuoteIdentifier ("modEfno"), "#D5"); Assert.AreEqual (" dEf", cb.QuoteIdentifier (string.Empty), "#D6"); Assert.AreEqual (" ZdEf", cb.QuoteIdentifier ("Z"), "#D7"); }
public void QuoteSuffix_UpdateCommand_Generated () { OdbcConnection conn = (OdbcConnection) ConnectionManager.Singleton.Connection; OdbcCommand cmd = null; try { string selectQuery = "select id, lname from employee where id = 3"; OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn); DataSet ds = new DataSet (); da.Fill (ds, "IntTest"); OdbcCommandBuilder cb = new OdbcCommandBuilder (da); cmd = cb.GetUpdateCommand (); Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#1"); try { cb.QuoteSuffix = ""; Assert.Fail ("#2"); } catch (InvalidOperationException ex) { // The QuotePrefix and QuoteSuffix properties // cannot be changed once an Insert, Update, or // Delete command has been generated Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3"); Assert.IsNull (ex.InnerException, "#4"); Assert.IsNotNull (ex.Message, "#5"); } Assert.AreEqual (string.Empty, cb.QuotePrefix, "#6"); cb.RefreshSchema (); cb.QuoteSuffix = ""; } finally { if (cmd != null) cmd.Dispose (); ConnectionManager.Singleton.CloseConnection (); } }
public void GetDeleteCommandTest () { OdbcConnection conn = (OdbcConnection) ConnectionManager.Singleton.Connection; OdbcCommand cmd = null; try { string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3"; OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn); DataSet ds = new DataSet (); da.Fill (ds, "IntTest"); Assert.AreEqual (1, ds.Tables.Count); OdbcCommandBuilder cb = new OdbcCommandBuilder (da); cmd = cb.GetDeleteCommand (); Assert.AreEqual ("DELETE FROM employee WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))", cmd.CommandText, "#A1"); Assert.AreSame (conn, cmd.Connection, "#A2"); AssertDeleteParameters (cmd, "#A3:"); cb = new OdbcCommandBuilder (da); cb.QuotePrefix = "\""; cmd = cb.GetDeleteCommand (); Assert.AreEqual ("DELETE FROM \"employee WHERE ((\"id = ?) AND ((? = 1 AND \"lname IS NULL) OR (\"lname = ?)))", cmd.CommandText, "#B1"); Assert.AreSame (conn, cmd.Connection, "#B2"); AssertDeleteParameters (cmd, "#B3:"); cb = new OdbcCommandBuilder (da); cb.QuoteSuffix = "´"; cmd = cb.GetDeleteCommand (); Assert.AreEqual ("DELETE FROM employee´ WHERE ((id´ = ?) AND ((? = 1 AND lname´ IS NULL) OR (lname´ = ?)))", cmd.CommandText, "#C1"); Assert.AreSame (conn, cmd.Connection, "#C2"); AssertDeleteParameters (cmd, "#C3:"); cb = new OdbcCommandBuilder (da); cb.QuotePrefix = "\""; cb.QuoteSuffix = "´"; cmd = cb.GetDeleteCommand (); Assert.AreEqual ("DELETE FROM \"employee´ WHERE ((\"id´ = ?) AND ((? = 1 AND \"lname´ IS NULL) OR (\"lname´ = ?)))", cmd.CommandText, "#D1"); Assert.AreSame (conn, cmd.Connection, "#D2"); AssertDeleteParameters (cmd, "#D3:"); } finally { if (cmd != null) cmd.Dispose (); ConnectionManager.Singleton.CloseConnection (); } }
public void GetInsertCommandTest_option_false () { OdbcConnection conn = (OdbcConnection) ConnectionManager.Singleton.Connection; try { string selectQuery = "select id, lname from employee where id = 3"; OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn); DataSet ds = new DataSet (); da.Fill (ds, "IntTest"); Assert.AreEqual (1, ds.Tables.Count); OdbcCommandBuilder cb = new OdbcCommandBuilder (da); OdbcCommand cmd = cb.GetInsertCommand (false); Assert.AreEqual ("INSERT INTO employee (id, lname) VALUES (?, ?)", cmd.CommandText, "#1"); Assert.AreSame (conn, cmd.Connection, "#2"); AssertInsertParameters (cmd, "#3:"); } finally { ConnectionManager.Singleton.CloseConnection (); } }
public void GetInsertCommandTestWithExpression () { if (ConnectionManager.Singleton.Engine.Type == EngineType.MySQL) Assert.Ignore ("Schema info from MySQL is incomplete"); OdbcConnection conn = (OdbcConnection) ConnectionManager.Singleton.Connection; OdbcCommand cmd = null; try { string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3"; OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn); DataSet ds = new DataSet (); da.Fill (ds, "IntTest"); Assert.AreEqual (1, ds.Tables.Count); OdbcCommandBuilder cb = new OdbcCommandBuilder (da); cmd = cb.GetInsertCommand (); Assert.AreEqual ("INSERT INTO employee (id, lname) VALUES (?, ?)", cmd.CommandText, "#1"); Assert.AreSame (conn, cmd.Connection, "#2"); AssertInsertParameters (cmd, "#3:"); } finally { if (cmd != null) cmd.Dispose (); ConnectionManager.Singleton.CloseConnection (); } }
// Sauvegarde tous les changements effectué dans le dataset public void SaveDataSet(string tableName, DataSet dataSet) { if (dataSet.HasChanges() == false) return; switch (connType) { case ConnectionType.DATABASE_MSSQL: { try { var conn = new SqlConnection(connString); var adapter = new SqlDataAdapter("SELECT * from " + tableName, conn); var builder = new SqlCommandBuilder(adapter); adapter.DeleteCommand = builder.GetDeleteCommand(); adapter.UpdateCommand = builder.GetUpdateCommand(); adapter.InsertCommand = builder.GetInsertCommand(); lock (dataSet) // lock dataset to prevent changes to it { adapter.ContinueUpdateOnError = true; DataSet changes = dataSet.GetChanges(); adapter.Update(changes, tableName); PrintDatasetErrors(changes); dataSet.AcceptChanges(); } conn.Close(); } catch (Exception ex) { throw new DatabaseException("Can not save table " + tableName, ex); } break; } case ConnectionType.DATABASE_ODBC: { try { var conn = new OdbcConnection(connString); var adapter = new OdbcDataAdapter("SELECT * from " + tableName, conn); var builder = new OdbcCommandBuilder(adapter); adapter.DeleteCommand = builder.GetDeleteCommand(); adapter.UpdateCommand = builder.GetUpdateCommand(); adapter.InsertCommand = builder.GetInsertCommand(); DataSet changes; lock (dataSet) // lock dataset to prevent changes to it { adapter.ContinueUpdateOnError = true; changes = dataSet.GetChanges(); adapter.Update(changes, tableName); dataSet.AcceptChanges(); } PrintDatasetErrors(changes); conn.Close(); } catch (Exception ex) { throw new DatabaseException("Can not save table ", ex); } break; } case ConnectionType.DATABASE_MYSQL: { return; } case ConnectionType.DATABASE_OLEDB: { try { var conn = new OleDbConnection(connString); var adapter = new OleDbDataAdapter("SELECT * from " + tableName, conn); var builder = new OleDbCommandBuilder(adapter); adapter.DeleteCommand = builder.GetDeleteCommand(); adapter.UpdateCommand = builder.GetUpdateCommand(); adapter.InsertCommand = builder.GetInsertCommand(); DataSet changes; lock (dataSet) // lock dataset to prevent changes to it { adapter.ContinueUpdateOnError = true; changes = dataSet.GetChanges(); adapter.Update(changes, tableName); dataSet.AcceptChanges(); } PrintDatasetErrors(changes); conn.Close(); } catch (Exception ex) { throw new DatabaseException("Can not save table", ex); } break; } } }
/// <summary> /// Obtain a data adapter for the specified Table /// </summary> /// <param name="tableName">Name of the table to obtain the /// adapter for</param> /// <returns>Adapter object for the specified table</returns> /// <remarks>An adapter serves as a bridge between a DataSet (in memory /// representation of table) and the data source</remarks> private OdbcDataAdapter GetAdapterForTable(string tableName) { OdbcDataAdapter da = null; AccessDBPSDriveInfo di = this.PSDriveInfo as AccessDBPSDriveInfo; if (di == null || !TableNameIsValid(tableName) || !TableIsPresent(tableName)) { return null; } OdbcConnection connection = di.Connection; try { // Create a odbc data adpater. This can be sued to update the // data source with the records that will be created here // using data sets string sql = "Select * from " + tableName; da = new OdbcDataAdapter(new OdbcCommand(sql, connection)); // Create a odbc command builder object. This will create sql // commands automatically for a single table, thus // eliminating the need to create new sql statements for // every operation to be done. OdbcCommandBuilder cmd = new OdbcCommandBuilder(da); // Open the connection if its not already open if (connection.State != ConnectionState.Open) { connection.Open(); } } catch (Exception e) { WriteError(new ErrorRecord(e, "CannotAccessSpecifiedTable", ErrorCategory.InvalidOperation, tableName)); } return da; }
public void ConflictOptionTest () { OdbcCommandBuilder cb = new OdbcCommandBuilder (); Assert.AreEqual (ConflictOption.CompareAllSearchableValues, cb.ConflictOption, "#1"); cb.ConflictOption = ConflictOption.CompareRowVersion; Assert.AreEqual (ConflictOption.CompareRowVersion, cb.ConflictOption, "#2"); }
[Test] // QuoteIdentifier (String, OdbcConnection) public void QuoteIdentifier2_Connection_Closed () { OdbcCommandBuilder cb; OdbcConnection conn = new OdbcConnection (); cb = new OdbcCommandBuilder (); try { cb.QuoteIdentifier ("mono", conn); Assert.Fail ("#A1"); } catch (InvalidOperationException ex) { // QuoteIdentifier requires an open and available // Connection. The connection's current state is // closed Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2"); Assert.IsNull (ex.InnerException, "#A3"); Assert.IsNotNull (ex.Message, "#A4"); } cb = new OdbcCommandBuilder (); cb.QuotePrefix = "abc"; Assert.AreEqual ("abcmono", cb.QuoteIdentifier ("mono", conn), "#B1"); Assert.AreEqual ("abcZ", cb.QuoteIdentifier ("Z", conn), "#B2"); Assert.AreEqual ("abcabc", cb.QuoteIdentifier ("abc", conn), "#B3"); Assert.AreEqual ("abc", cb.QuoteIdentifier (string.Empty, conn), "#B4"); Assert.AreEqual ("abc ", cb.QuoteIdentifier (" ", conn), "#B5"); Assert.AreEqual ("abc\r", cb.QuoteIdentifier ("\r", conn), "#B6"); cb.QuoteSuffix = "def"; Assert.AreEqual ("abcmonodef", cb.QuoteIdentifier ("mono", conn), "#B7"); Assert.AreEqual ("abcZdef", cb.QuoteIdentifier ("Z", conn), "#B8"); Assert.AreEqual ("abcabcdef", cb.QuoteIdentifier ("abc", conn), "#B9"); Assert.AreEqual ("abcdef", cb.QuoteIdentifier (string.Empty, conn), "#B10"); Assert.AreEqual ("abc def", cb.QuoteIdentifier (" ", conn), "#B11"); Assert.AreEqual ("abc\rdef", cb.QuoteIdentifier ("\r", conn), "#B12"); cb.QuotePrefix = string.Empty; try { cb.QuoteIdentifier ("mono"); Assert.Fail ("#C1"); } catch (InvalidOperationException ex) { // QuoteIdentifier requires an open and available // Connection. The connection's current state is // closed Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2"); Assert.IsNull (ex.InnerException, "#C3"); Assert.IsNotNull (ex.Message, "#C4"); } cb = new OdbcCommandBuilder (); cb.QuotePrefix = "X"; Assert.AreEqual ("Xmono", cb.QuoteIdentifier ("mono"), "#D1"); Assert.AreEqual ("XZ", cb.QuoteIdentifier ("Z"), "#D2"); Assert.AreEqual ("XX", cb.QuoteIdentifier ("X"), "#D3"); Assert.AreEqual ("X", cb.QuoteIdentifier (string.Empty, conn), "#D4"); Assert.AreEqual ("X ", cb.QuoteIdentifier (" ", conn), "#D5"); Assert.AreEqual ("X\r", cb.QuoteIdentifier ("\r", conn), "#D6"); cb.QuoteSuffix = " "; Assert.AreEqual ("Xmono ", cb.QuoteIdentifier ("mono"), "#D7"); Assert.AreEqual ("XZ ", cb.QuoteIdentifier ("Z"), "#D8"); Assert.AreEqual ("XX ", cb.QuoteIdentifier ("X"), "#D9"); Assert.AreEqual ("X ", cb.QuoteIdentifier (string.Empty, conn), "#D10"); Assert.AreEqual ("X ", cb.QuoteIdentifier (" ", conn), "#D11"); Assert.AreEqual ("X\r ", cb.QuoteIdentifier ("\r", conn), "#D12"); cb = new OdbcCommandBuilder (); cb.QuotePrefix = " "; Assert.AreEqual ("mono", cb.QuoteIdentifier ("mono", conn), "#E1"); Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z", conn), "#E2"); Assert.AreEqual ("abc", cb.QuoteIdentifier ("abc", conn), "#E3"); Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty, conn), "#E4"); Assert.AreEqual (" ", cb.QuoteIdentifier (" ", conn), "#E5"); Assert.AreEqual ("\r", cb.QuoteIdentifier ("\r", conn), "#E6"); cb.QuoteSuffix = "def"; Assert.AreEqual ("mono", cb.QuoteIdentifier ("mono", conn), "#E7"); Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z", conn), "#E8"); Assert.AreEqual ("abc", cb.QuoteIdentifier ("abc", conn), "#E9"); Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty, conn), "#E10"); Assert.AreEqual (" ", cb.QuoteIdentifier (" ", conn), "#E11"); Assert.AreEqual ("\r", cb.QuoteIdentifier ("\r", conn), "#E12"); }
[Test] // QuoteIdentifier (String) public void QuoteIdentifier1_UnquotedIdentifier_Null () { OdbcCommandBuilder cb = new OdbcCommandBuilder (); try { cb.QuoteIdentifier ((string) null); Assert.Fail ("#1"); } catch (ArgumentNullException ex) { Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); Assert.AreEqual ("unquotedIdentifier", ex.ParamName, "#5"); } }
[Test] // QuoteIdentifier (String) public void QuoteIdentifier1_QuotePrefix_Empty () { OdbcCommandBuilder cb = new OdbcCommandBuilder (); try { cb.QuoteIdentifier ("mono"); Assert.Fail ("#1"); } catch (InvalidOperationException ex) { // QuoteIdentifier requires open connection when // the quote prefix has not been set Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); } }
public virtual void SelectAll() { //Connection string for MyODBC 3.51 /*myOdbcConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=" + database + ";" + "UID=" + user + ";" + "PASSWORD="******";" + "OPTION=3"; */ //check Odbc Connection if (myOdbcConnection == null) throw new Exception("No connection established."); try { //no need to open the connection manually, DataAdapter will open //and close it automatically, in fact it is recommended not to //explicity open the connection: in case of an error, raised by //the DataAdapter.Fill() or DataAdapter.Update() method, the connection //will stay open //myOdbcConnection.Open(); //read all Datasets from table OdbcCommand myOdbcCommand = new OdbcCommand("SELECT * FROM " + table, myOdbcConnection); myOdbcDataAdapter = new OdbcDataAdapter(); myOdbcDataAdapter.SelectCommand = myOdbcCommand; //Create CommandBuilder to generate Update/Delete/Insert-Commands for writeToDb() OdbcCommandBuilder myOdbcCommandBuilder = new OdbcCommandBuilder(myOdbcDataAdapter); //Add Tablenames to Dataset myOdbcDataAdapter.TableMappings.Clear(); myOdbcDataAdapter.TableMappings.Add("Table", table); //fill DataSet myOdbcDataAdapter.Fill(dataSet, table); //connection established isConnected = true; } catch (OdbcException e) { for (int i=0; i < e.Errors.Count; i++) { Trace.WriteLine("Odbc-Error #" + i + ":", "Error"); Trace.WriteLine("Message: " + e.Errors[i].Message, "Error"); Trace.WriteLine("Native: " + e.Errors[i].NativeError.ToString(), "Error"); Trace.WriteLine("Source: " + e.Errors[i].Source, "Error"); Trace.WriteLine("SQL: " + e.Errors[i].SQLState, "Error"); } //return with error isConnected=false; } finally { //myOdbcConnection.Close(); } }
public virtual void SelectAll(string orderBy) { //check Odbc Connection if (myOdbcConnection == null) throw new Exception("No connection established."); try { //no need to open the connection manually, DataAdapter will open //and close it automatically, in fact it is recommended not to //explicity open the connection: in case of an error, raised by //the DataAdapter.Fill() or DataAdapter.Update() method, the connection //will stay open //myOdbcConnection.Open(); //read all datasets (rows) from table OdbcCommand myOdbcCommand = new OdbcCommand("SELECT * FROM " + table + " ORDER BY " + orderBy, myOdbcConnection); myOdbcDataAdapter = new OdbcDataAdapter(); myOdbcDataAdapter.SelectCommand = myOdbcCommand; //Create CommandBuilder to automatically generate Update/Delete/Insert-Commands //for DataAdapter used by method writeToDb() OdbcCommandBuilder myOdbcCommandBuilder = new OdbcCommandBuilder(myOdbcDataAdapter); //Add Tablenames to Dataset myOdbcDataAdapter.TableMappings.Clear(); myOdbcDataAdapter.TableMappings.Add("Table", table); //fill DataSet myOdbcDataAdapter.Fill(dataSet, table); //connection established isConnected = true; } catch (OdbcException e) { for (int i=0; i < e.Errors.Count; i++) { Trace.WriteLine("Odbc-Error #" + i + ":", "Error"); Trace.WriteLine("Message: " + e.Errors[i].Message, "Error"); Trace.WriteLine("Native: " + e.Errors[i].NativeError.ToString(), "Error"); Trace.WriteLine("Source: " + e.Errors[i].Source, "Error"); Trace.WriteLine("SQL: " + e.Errors[i].SQLState, "Error"); } //connection not established isConnected = false; } finally { //myOdbcConnection.Close(); } }
public void ConflictOption_Value_Invalid () { OdbcCommandBuilder cb = new OdbcCommandBuilder (); cb.ConflictOption = ConflictOption.CompareRowVersion; try { cb.ConflictOption = (ConflictOption) 666; Assert.Fail ("#1"); } catch (ArgumentOutOfRangeException ex) { // The ConflictOption enumeration value, 666, is invalid Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); Assert.IsTrue (ex.Message.IndexOf ("ConflictOption") != -1, "#5:" + ex.Message); Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6:" + ex.Message); Assert.AreEqual ("ConflictOption", ex.ParamName, "#7"); } Assert.AreEqual (ConflictOption.CompareRowVersion, cb.ConflictOption, "#8"); }
} // RemoveTable /// <summary> /// Obtain a data adapter for the specified Table /// </summary> /// <param name="tableName">Name of the table to obtain the /// adapter for</param> /// <returns>Adapter object for the specified table</returns> /// <remarks>An adapter serves as a bridge between a DataSet (in memory /// representation of table) and the data source</remarks> internal OdbcDataAdapter GetAdapterForTable(string tableName) { OdbcDataAdapter da = null; AccessDBPSDriveInfo di = this.PSDriveInfo as AccessDBPSDriveInfo; if (di == null || !TableNameIsValid(tableName) || !TableIsPresent(tableName)) { return null; } OdbcConnection connection = di.Connection; try { // Create a odbc data adpater. This can be sued to update the // data source with the records that will be created here // using data sets string sql = "Select * from " + tableName; da = new OdbcDataAdapter(new OdbcCommand(sql, connection)); // Create a odbc command builder object. This will create sql // commands automatically for a single table, thus // eliminating the need to create new sql statements for // every operation to be done. OdbcCommandBuilder cmd = new OdbcCommandBuilder(da); // Set the delete cmd for the table here sql = "Delete from " + tableName + " where ID = ?"; da.DeleteCommand = new OdbcCommand(sql, connection); // Specify a DeleteCommand parameter based on the "ID" // column da.DeleteCommand.Parameters.Add(new OdbcParameter()); da.DeleteCommand.Parameters[0].SourceColumn = "ID"; // Create an InsertCommand based on the sql string // Insert into "tablename" values (?,?,?)" where // ? represents a column in the table. Note that // the number of ? will be equal to the number of // columnds DataSet ds = new DataSet(); ds.Locale = CultureInfo.InvariantCulture; da.FillSchema(ds, SchemaType.Source); sql = "Insert into " + tableName + " values ( "; for (int i = 0; i < ds.Tables["Table"].Columns.Count; i++) { sql += "?, "; } sql = sql.Substring(0, sql.Length - 2); sql += ")"; da.InsertCommand = new OdbcCommand(sql, connection); // Create parameters for the InsertCommand based on the // captions of each column for (int i = 0; i < ds.Tables["Table"].Columns.Count; i++) { da.InsertCommand.Parameters.Add(new OdbcParameter()); da.InsertCommand.Parameters[i].SourceColumn = ds.Tables["Table"].Columns[i].Caption; } // Open the connection if its not already open if (connection.State != ConnectionState.Open) { connection.Open(); } } catch (Exception e) { WriteError(new ErrorRecord(e, "CannotAccessSpecifiedTable", ErrorCategory.InvalidOperation, tableName)); } return da; } // GetAdapterForTable
public void RetrieveOdbcData(string sql) { this.odbcadapter = new OdbcDataAdapter(sql, (OdbcConnection)this.conn); this.odbcbuilder = new OdbcCommandBuilder(this.odbcadapter); ds = new DataSet(); this.odbcadapter.Fill(ds, tablename); }
protected override DbDataAdapter GetDataAdapter(string tableName, string schemaName, out DbCommandBuilder builder) { var adapter = new OdbcDataAdapter(string.Format(CultureInfo.InvariantCulture, "SELECT * FROM \"{0}\" ORDER BY 1", tableName), OdbcConnectionString); builder = new OdbcCommandBuilder(adapter); return adapter; }
public void SaveDataSetThroughAdapter(System.Data.DataSet dsSetRef, Boolean blnRequiredTransaction, String ExcludeTableName, String strConName) { Boolean blnBeginTrans = false; OleDbDataAdapter objOleDBAdpater; OdbcDataAdapter objOdbcDBAdpater; SqlDataAdapter objSqlDBAdpater; OdbcCommandBuilder objOdbcDBCommandBuilder; OleDbCommandBuilder objOleDBCommandBuilder; SqlCommandBuilder objSqlDBCommandBuilder; IDbCommand IMainCommand; DataTable dtInsert; DataTable dtUpdate; DataTable dtDelete; Boolean TableExist; String strQuery; try { if (dsSetRef == null) { throw new Exception("DataSet not Initialized"); } String[] TableName; char[] delimeter; String seperator; seperator = ","; delimeter = seperator.ToCharArray(); TableName = ExcludeTableName.Split(delimeter); if (blnRequiredTransaction.IsFalse()) { if (strConName.Length > 0) { OpenConnection(strConName); } else { OpenConnection(String.Empty); } } if (disconnection.IsNotNull()) { if (blnRequiredTransaction.IsFalse()) { transaction = disconnection.BeginTransaction(IsolationLevel.ReadUncommitted); blnBeginTrans = true; } else { if (transaction == null) { throw new Exception("Transaction is not initialized"); } else { blnBeginTrans = true; } } if (ProviderType == Util.ConnectionLibrary.SQlClient) { IMainCommand = new SqlCommand(); } else if (ProviderType == Util.ConnectionLibrary.Oledb) { IMainCommand = new OleDbCommand(); } else if (ProviderType == Util.ConnectionLibrary.ODBC) { IMainCommand = new OdbcCommand(); } else { IMainCommand = null; } IMainCommand.Connection = disconnection; IMainCommand.Transaction = transaction; } else { throw new Exception("Connection is not initialized"); } IMainCommand.CommandTimeout = CommandTimeOutValue; foreach (DataTable dtRef in dsSetRef.Tables) { TableExist = false; foreach (String tablename in TableName) { if (dtRef.TableName.ToUpper() == tablename.ToUpper()) { TableExist = true; break; } } if (TableExist) continue; if ((Boolean)dtRef.ExtendedProperties[JoinedQuery]) { strQuery = dtRef.ExtendedProperties[UpdateQuery].ToString(); } else { strQuery = dtRef.ExtendedProperties[Query].ToString(); } if ((strQuery.Trim()).Length == 0) { throw new Exception("Query is blank"); } IMainCommand.CommandText = strQuery; dtInsert = dtRef.GetChanges(DataRowState.Added); dtUpdate = dtRef.GetChanges(DataRowState.Modified); dtDelete = dtRef.GetChanges(DataRowState.Deleted); if (ProviderType == Util.ConnectionLibrary.SQlClient) { objSqlDBAdpater = new SqlDataAdapter((SqlCommand)IMainCommand); objSqlDBCommandBuilder = new SqlCommandBuilder(objSqlDBAdpater); if (dtDelete.IsNotNull()) { objSqlDBCommandBuilder.GetDeleteCommand(); objSqlDBAdpater.Update(dtDelete); dtDelete.Dispose(); dtDelete = null; } if (dtInsert.IsNotNull()) { objSqlDBCommandBuilder.GetInsertCommand(); objSqlDBAdpater.Update(dtInsert); dtInsert.Dispose(); dtInsert = null; } if (dtUpdate.IsNotNull()) { objSqlDBCommandBuilder.GetUpdateCommand(); objSqlDBAdpater.Update(dtUpdate); dtUpdate.Dispose(); dtUpdate = null; } } else if (ProviderType == Util.ConnectionLibrary.Oledb) { objOleDBAdpater = new OleDbDataAdapter((OleDbCommand)IMainCommand); objOleDBCommandBuilder = new OleDbCommandBuilder(objOleDBAdpater); if (dtInsert.IsNotNull()) { objOleDBCommandBuilder.GetInsertCommand(); objOleDBAdpater.Update(dtInsert); dtInsert.Dispose(); dtInsert = null; } if (dtUpdate.IsNotNull()) { objOleDBCommandBuilder.GetUpdateCommand(); objOleDBAdpater.Update(dtUpdate); dtUpdate.Dispose(); dtUpdate = null; } if (dtDelete.IsNotNull()) { objOleDBCommandBuilder.GetDeleteCommand(); objOleDBAdpater.Update(dtDelete); dtDelete.Dispose(); dtDelete = null; } } else if (ProviderType == Util.ConnectionLibrary.ODBC) { objOdbcDBAdpater = new OdbcDataAdapter((OdbcCommand)IMainCommand); objOdbcDBCommandBuilder = new OdbcCommandBuilder(objOdbcDBAdpater); if (dtInsert.IsNotNull()) { objOdbcDBCommandBuilder.GetInsertCommand(); objOdbcDBAdpater.Update(dtInsert); dtInsert.Dispose(); dtInsert = null; } if (dtUpdate.IsNotNull()) { objOdbcDBCommandBuilder.GetUpdateCommand(); objOdbcDBAdpater.Update(dtUpdate); dtUpdate.Dispose(); dtUpdate = null; } if (dtDelete.IsNotNull()) { objOdbcDBCommandBuilder.GetDeleteCommand(); objOdbcDBAdpater.Update(dtDelete); dtDelete.Dispose(); dtDelete = null; } } else { objSqlDBAdpater = null; objOleDBAdpater = null; objOdbcDBAdpater = null; objSqlDBCommandBuilder = null; objOleDBCommandBuilder = null; objOdbcDBCommandBuilder = null; } } if (blnRequiredTransaction.IsFalse()) { if (blnBeginTrans) { transaction.Commit(); blnBeginTrans = false; } disconnection.Close(); disconnection.Dispose(); disconnection = null; } } catch (System.Data.OleDb.OleDbException exOleDb) { if (blnBeginTrans && blnRequiredTransaction.IsFalse()) { transaction.Rollback(); if (disconnection.IsNotNull()) { if (disconnection.State == System.Data.ConnectionState.Open) { disconnection.Close(); } disconnection.Dispose(); disconnection = null; } } throw (exOleDb); } catch (System.Data.DBConcurrencyException exDBCE) { if (blnBeginTrans && blnRequiredTransaction.IsFalse()) { transaction.Rollback(); if (disconnection.IsNotNull()) { if (disconnection.State == System.Data.ConnectionState.Open) { disconnection.Close(); } disconnection.Dispose(); disconnection = null; } } throw (exDBCE); } catch (System.Exception ex) { if (blnBeginTrans && blnRequiredTransaction.IsFalse()) { transaction.Rollback(); if (disconnection.IsNotNull()) { if (disconnection.State == System.Data.ConnectionState.Open) { disconnection.Close(); } disconnection.Dispose(); disconnection = null; } } throw (ex); } finally { if (ProviderType == Util.ConnectionLibrary.SQlClient) { IMainCommand = null; objSqlDBAdpater = null; objSqlDBCommandBuilder = null; } else if (ProviderType == Util.ConnectionLibrary.Oledb) { IMainCommand = null; objOleDBAdpater = null; objOleDBCommandBuilder = null; } else if (ProviderType == Util.ConnectionLibrary.ODBC) { IMainCommand = null; objOdbcDBAdpater = null; objOdbcDBCommandBuilder = null; } } }
public void GetUpdateCommandDBConcurrencyExceptionTest () { OdbcConnection conn = (OdbcConnection) ConnectionManager.Singleton.Connection; try { string selectQuery = "select id, lname from employee where id = 3"; OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn); DataSet ds = new DataSet (); da.Fill (ds, "IntTest"); Assert.AreEqual (1, ds.Tables.Count); OdbcCommandBuilder cb = new OdbcCommandBuilder (da); Assert.IsNotNull (cb); DataRow [] rows = ds.Tables [0].Select ("id=1"); rows [0] [0] = 6660; // non existent ds.Tables [0].AcceptChanges (); // moves 6660 to original value rows [0] [0] = 1; // moves 6660 as search key into db table try { da.Update (rows); Assert.Fail ("#1"); } catch (DBConcurrencyException ex) { // Concurrency violation: the UpdateCommand // affected 0 records Assert.AreEqual (typeof (DBConcurrencyException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); Assert.AreSame (rows [0], ex.Row, "#5"); Assert.AreEqual (1, ex.RowCount, "#6"); } } finally { ConnectionManager.Singleton.CloseConnection (); } }
private void LoadMarksSheet(string filename, OdbcConnection conn) { OdbcDataAdapter conncmd; using (DataTable table = new DataTable()) { using (OdbcCommandBuilder bldr = new OdbcCommandBuilder()) { using (conncmd = new OdbcDataAdapter("SELECT * FROM " + bldr.QuoteIdentifier("Marks", conn), conn)) { conncmd.Fill(table); } } if (table.Columns.Contains("Name")) { LoadDataTable(filename, table); } } }
public void GetDeleteCommandTest_option_false () { OdbcConnection conn = (OdbcConnection) ConnectionManager.Singleton.Connection; try { string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3"; OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn); DataSet ds = new DataSet (); da.Fill (ds, "IntTest"); Assert.AreEqual (1, ds.Tables.Count); OdbcCommandBuilder cb = new OdbcCommandBuilder (da); OdbcCommand cmd = cb.GetDeleteCommand (false); Assert.AreEqual ("DELETE FROM employee WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))", cmd.CommandText, "#1"); Assert.AreSame (conn, cmd.Connection, "#2"); AssertDeleteParameters (cmd, "#3:"); } finally { ConnectionManager.Singleton.CloseConnection (); } }
public override DbCommandBuilder MakeCommandBuilder() { OdbcCommandBuilder odbcbuilder = new OdbcCommandBuilder(); return odbcbuilder; }
public ExcelWorksheet(string sheet, OdbcConnection conn) { //this.BeginInit(); OdbcDataAdapter conncmd; using (DataTable table = new DataTable()) { using (OdbcCommandBuilder bldr = new OdbcCommandBuilder()) { using (conncmd = new OdbcDataAdapter("SELECT * FROM " + bldr.QuoteIdentifier(sheet, conn), conn)) { conncmd.Fill(table); } } this.Load(table); } //this.EndInit(); }
public void GenericExportCSV() { string sql = ConfigurationManager.ConnectionStrings["odbc"].ConnectionString; OdbcConnection cn = null; try { using (cn = new OdbcConnection(sql)) { cn.Open(); DataSet CustomersDataSet = new DataSet(); using (OdbcDataAdapter da_local = new OdbcDataAdapter(String.Format("SELECT * FROM RREV.{0}", Table), cn)) { using (OdbcCommandBuilder cmdBuilder = new OdbcCommandBuilder(da_local)) { OdbcCommand schemaCommand = new OdbcCommand(String.Format("SELECT * FROM RREV.{0} WHERE 1=0", Table), cn); OdbcDataReader reader = schemaCommand.ExecuteReader(); DataTable schemaTable = reader.GetSchemaTable(); FixedLengthClassBuilder cb = new FixedLengthClassBuilder(Table); //cb.IgnoreFirstLines = 1; cb.IgnoreEmptyLines = true; //// populate the fields based on the columns foreach (DataRow row in schemaTable.Rows) { string fieldName = row.Field<string>("ColumnName"); Type fieldType = row.Field<Type>("DataType"); int fieldLength = row.Field<int>("ColumnSize"); FixedFieldBuilder fb = cb.AddField(fieldName, fieldLength, fieldType); fb.FieldOptional = row.Field<bool>("AllowDBNull"); int NumericPrecision = row.Field<int>("NumericPrecision"); //Converterb //ConverterBuilder cb = new ConverterBuilder(); //fb.Converter = new MoneyConverter(NumericPrecision); //fb.FieldIndex = row.Field<int>("ColumnOrdinal"); //fb.Converter = //- Results View Expanding the Results View will enumerate the IEnumerable //+ [0] {ColumnName} object {System.Data.DataColumn} //+ [1] {ColumnOrdinal} object {System.Data.DataColumn} //+ [2] {ColumnSize} object {System.Data.DataColumn} //+ [3] {NumericPrecision} object {System.Data.DataColumn} //+ [4] {NumericScale} object {System.Data.DataColumn} //+ [5] {DataType} object {System.Data.DataColumn} //+ [6] {ProviderType} object {System.Data.DataColumn} //+ [7] {IsLong} object {System.Data.DataColumn} //+ [8] {AllowDBNull} object {System.Data.DataColumn} //+ [9] {IsReadOnly} object {System.Data.DataColumn} //+ [10] {IsRowVersion} object {System.Data.DataColumn} //+ [11] {IsUnique} object {System.Data.DataColumn} //+ [12] {IsKey} object {System.Data.DataColumn} //+ [13] {IsAutoIncrement} object {System.Data.DataColumn} //+ [14] {BaseSchemaName} object {System.Data.DataColumn} //+ [15] {BaseCatalogName} object {System.Data.DataColumn} //+ [16] {BaseTableName} object {System.Data.DataColumn} //+ [17] {BaseColumnName} object {System.Data.DataColumn} //+ Constraints {System.Data.ConstraintCollection} System.Data.ConstraintCollection } reader.Close(); string classFileName = String.Format("e:\\temp\\db_dump\\{0}.xml", Table); cb.SaveToXml(classFileName); da_local.Fill(CustomersDataSet, Table); DataTable dt = CustomersDataSet.Tables[Table]; //http://stackoverflow.com/questions/8725225/how-to-use-a-dynamic-csv-delimiter-with-filehelpers log4net.LogManager.GetLogger(this.GetType()).InfoFormat("{0} num rows: {1}", Table, dt.Rows.Count); CsvEngine.DataTableToCsv(dt, Path.Combine("e:\\temp\\db_dump\\", Table)); //DataTable schemaTable = reader.GetSchemaTable(); cn.Close(); //// create the FileHelpers record class //// alternatively there is a 'FixedClassBuilder' //DelimitedClassBuilder cb = new DelimitedClassBuilder("UnitTask", ","); //cb.IgnoreFirstLines = 1; //cb.IgnoreEmptyLines = true; //// populate the fields based on the columns //foreach (DataRow row in schemaTable.Rows) //{ // cb.AddField(row.Field<string>("ColumnName"), row.Field<Type>("DataType")); // cb.LastField.TrimMode = TrimMode.Both; //} //reader.Close(); //// load the dynamically created class into a FileHelpers engine //FileHelperEngine engine = new FileHelperEngine(cb.CreateRecordClass()); } } } } catch (Exception ex) { } finally { if (cn != null && cn.State == ConnectionState.Open) { cn.Close(); } } }
[Test] // QuoteIdentifier (String, OdbcConnection) public void QuoteIdentifier2 () { OdbcCommandBuilder cb; OdbcConnection conn = (OdbcConnection) ConnectionManager.Singleton.Connection; ConnectionManager.Singleton.OpenConnection (); string quote_char = ConnectionManager.Singleton.Engine.QuoteCharacter; try { cb = new OdbcCommandBuilder (); Assert.AreEqual (quote_char + "mono" + quote_char, cb.QuoteIdentifier ("mono", conn), "#A1"); Assert.AreEqual (quote_char + "Z" + quote_char, cb.QuoteIdentifier ("Z", conn), "#A2"); Assert.AreEqual (quote_char + "abc" + quote_char, cb.QuoteIdentifier ("abc", conn), "#A3"); Assert.AreEqual (quote_char + quote_char, cb.QuoteIdentifier (string.Empty, conn), "#A4"); Assert.AreEqual (quote_char + " " + quote_char, cb.QuoteIdentifier (" ", conn), "#A5"); Assert.AreEqual (quote_char + "\r" + quote_char, cb.QuoteIdentifier ("\r", conn), "#A6"); cb.QuoteSuffix = "def"; Assert.AreEqual (quote_char + "mono" + quote_char, cb.QuoteIdentifier ("mono", conn), "#A7"); Assert.AreEqual (quote_char + "Z" + quote_char, cb.QuoteIdentifier ("Z", conn), "#A8"); Assert.AreEqual (quote_char + "abc" + quote_char, cb.QuoteIdentifier ("abc", conn), "#A9"); Assert.AreEqual (quote_char + quote_char, cb.QuoteIdentifier (string.Empty, conn), "#A10"); Assert.AreEqual (quote_char + " " + quote_char, cb.QuoteIdentifier (" ", conn), "#A11"); Assert.AreEqual (quote_char + "\r" + quote_char, cb.QuoteIdentifier ("\r", conn), "#A12"); cb = new OdbcCommandBuilder (); cb.QuotePrefix = "abc"; Assert.AreEqual ("abcmono", cb.QuoteIdentifier ("mono", conn), "#B1"); Assert.AreEqual ("abcZ", cb.QuoteIdentifier ("Z", conn), "#B2"); Assert.AreEqual ("abcabc", cb.QuoteIdentifier ("abc", conn), "#B3"); Assert.AreEqual ("abc", cb.QuoteIdentifier (string.Empty, conn), "#B4"); Assert.AreEqual ("abc ", cb.QuoteIdentifier (" ", conn), "#B5"); Assert.AreEqual ("abc\r", cb.QuoteIdentifier ("\r", conn), "#B6"); cb.QuoteSuffix = "def"; Assert.AreEqual ("abcmonodef", cb.QuoteIdentifier ("mono", conn), "#B7"); Assert.AreEqual ("abcZdef", cb.QuoteIdentifier ("Z", conn), "#B8"); Assert.AreEqual ("abcabcdef", cb.QuoteIdentifier ("abc", conn), "#B9"); Assert.AreEqual ("abcdef", cb.QuoteIdentifier (string.Empty, conn), "#B10"); Assert.AreEqual ("abc def", cb.QuoteIdentifier (" ", conn), "#B11"); Assert.AreEqual ("abc\rdef", cb.QuoteIdentifier ("\r", conn), "#B12"); cb.QuotePrefix = string.Empty; cb = new OdbcCommandBuilder (); cb.QuotePrefix = "X"; Assert.AreEqual ("Xmono", cb.QuoteIdentifier ("mono", conn), "#D1"); Assert.AreEqual ("XZ", cb.QuoteIdentifier ("Z", conn), "#D2"); Assert.AreEqual ("XX", cb.QuoteIdentifier ("X", conn), "#D3"); Assert.AreEqual ("X", cb.QuoteIdentifier (string.Empty, conn), "#D4"); Assert.AreEqual ("X ", cb.QuoteIdentifier (" ", conn), "#D5"); Assert.AreEqual ("X\r", cb.QuoteIdentifier ("\r", conn), "#D6"); cb.QuoteSuffix = " "; Assert.AreEqual ("Xmono ", cb.QuoteIdentifier ("mono", conn), "#D7"); Assert.AreEqual ("XZ ", cb.QuoteIdentifier ("Z", conn), "#D8"); Assert.AreEqual ("XX ", cb.QuoteIdentifier ("X", conn), "#D9"); Assert.AreEqual ("X ", cb.QuoteIdentifier (string.Empty, conn), "#D10"); Assert.AreEqual ("X ", cb.QuoteIdentifier (" ", conn), "#D11"); Assert.AreEqual ("X\r ", cb.QuoteIdentifier ("\r", conn), "#D12"); cb = new OdbcCommandBuilder (); cb.QuotePrefix = " "; Assert.AreEqual ("mono", cb.QuoteIdentifier ("mono", conn), "#E1"); Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z", conn), "#E2"); Assert.AreEqual ("abc", cb.QuoteIdentifier ("abc", conn), "#E3"); Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty, conn), "#E4"); Assert.AreEqual (" ", cb.QuoteIdentifier (" ", conn), "#E5"); Assert.AreEqual ("\r", cb.QuoteIdentifier ("\r", conn), "#E6"); cb.QuoteSuffix = "def"; Assert.AreEqual ("mono", cb.QuoteIdentifier ("mono", conn), "#E7"); Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z", conn), "#E8"); Assert.AreEqual ("abc", cb.QuoteIdentifier ("abc", conn), "#E9"); Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty, conn), "#E10"); Assert.AreEqual (" ", cb.QuoteIdentifier (" ", conn), "#E11"); Assert.AreEqual ("\r", cb.QuoteIdentifier ("\r", conn), "#E12"); } finally { ConnectionManager.Singleton.CloseConnection (); } }
public void QuoteSuffix () { OdbcCommandBuilder cb = new OdbcCommandBuilder (); Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#1"); cb.QuoteSuffix = "mono"; Assert.AreEqual ("mono", cb.QuoteSuffix, "#2"); cb.QuoteSuffix = null; Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#3"); cb.QuoteSuffix = "'\""; Assert.AreEqual ("'\"", cb.QuoteSuffix, "#4"); cb.QuoteSuffix = string.Empty; Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#5"); cb.QuoteSuffix = " "; Assert.AreEqual (" ", cb.QuoteSuffix, "#6"); }