Exemplo n.º 1
0
        public bool Parse()
        {
            try
            {
                //Fix for mysql.
                if (this._dbo.GetDatabaseConnector().getDBType() == DATABASETYPES.MYSQL)
                {
                    this._dbo.GetDatabaseConnector().executeNonQuery("SET AUTOCOMMIT = 0");
                    this._dbo.GetDatabaseConnector().executeNonQuery("BEGIN");

                }
                odt = this._dbo.GetDatabaseConnector().GetRawConnectionObject().BeginTransaction();
                this.oc = new OdbcCommand();
                oc.Connection = odt.Connection;
                oc.Transaction = odt;
                foreach (string sql in this._transList)
                {
                    //string tmpsql = this._dbo.CompileSQLToNative(sql);
                    string tmpsql = sql;
                    if ((tmpsql != "") && tmpsql.Length > 2)
                    {
                        if (this._dbo.GetDatabaseConnector().Open() != ERRORCODES.NONE)
                        {
                            throw (new Exception("Database connection lost."));
                        }
                        oc.CommandText = this._dbo.GetDatabaseConnector().DoTopLevelSqlTranslations(ref tmpsql);
                        oc.ExecuteNonQuery();
                    }
                }
                odt.Commit();
                if (this._dbo.GetDatabaseConnector().getDBType() == DATABASETYPES.MYSQL)
                this._dbo.GetDatabaseConnector().executeNonQuery("COMMIT");
                return true;
            }
            catch(Exception e)
            {
                if(e.Message.IndexOf("parallel transactions") > 0) {
                    // Start new connection and try again.
                    this._dbo = this._dbo.getNewConnection();
                    this.Parse();
                }
                if(this.dbParent.GetDatabaseConnector().GetRawConnectionObject().State == ConnectionState.Closed)
                this.dbParent.RaiseDBCloseClause();
                try
                {

                    odt.Rollback();
                    if (this._dbo.GetDatabaseConnector().getDBType() == DATABASETYPES.MYSQL)
                        this._dbo.GetDatabaseConnector().executeNonQuery("ROLLBACK");
                }
                catch { /**/ }
                this._errorState = 1;
                this._errorString = e.Message;
                return false;
            }
        }
Exemplo n.º 2
0
		public DataTable ExecuteTable(string tableName, string query, OdbcTransaction transaction)
		{
			try
			{
				OdbcCommand dbCommand = transaction.Connection.CreateCommand();
				dbCommand.Transaction = transaction;
				dbCommand.CommandText = query;

				OdbcDataAdapter dbDataAdapter = new OdbcDataAdapter(dbCommand);
				DataTable dataTable = new DataTable(tableName);

				dbDataAdapter.MissingSchemaAction = MissingSchemaAction.Add;
				dbDataAdapter.FillSchema(dataTable, SchemaType.Source);
				dbDataAdapter.Fill(dataTable);

				return dataTable;
			}
			catch (Exception)
			{
				transaction.Rollback();
				
				var trace = new System.Diagnostics.StackTrace(true);
				var frame = trace.GetFrame(0);
				var method = frame.GetMethod();
				return null;
			}
		}