Example #1
0
        public override int Execute()
        {
            CommandStatus ret = CommandStatus.E_OK;

            if (_sql.Trim().ToUpper().StartsWith("SELECT"))
            {
                ret = CommandStatus.E_FAIL_INVALID_SQL;
            }
            else
            {
                IConnection conn = null;
                try
                {
                    conn = CreateConnection(_prv, _connStr);
                    conn.Open();
                }
                catch (OSGeo.FDO.Common.Exception ex)
                {
                    WriteException(ex);
                    ret = CommandStatus.E_FAIL_CONNECT;
                }

                if (conn.ConnectionState == ConnectionState.ConnectionState_Open)
                {
                    try
                    {
                        var caps = conn.CommandCapabilities;
                        if (Array.IndexOf <int>(caps.Commands, (int)CommandType.CommandType_SQLCommand) < 0)
                        {
                            ret = CommandStatus.E_FAIL_SQL_COMMAND_NOT_SUPPORTED;
                        }
                        else
                        {
                            using (ISQLCommand cmd = (ISQLCommand)conn.CreateCommand(CommandType.CommandType_SQLCommand))
                            {
                                cmd.SQLStatement = _sql;
                                try
                                {
                                    cmd.ExecuteNonQuery();
                                }
                                catch (Exception ex)
                                {
                                    WriteException(ex);
                                    ret = CommandStatus.E_FAIL_SQL_EXECUTION_ERROR;
                                }
                            }
                        }
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            return((int)ret);
        }