private DataView ConsultarDataViewDaConsultaAtual(out int top)
        {
            var view      = ConsultarTabelaComDadosVirtuais().DefaultView;
            var sql       = CommandText.ToLower();
            var indiceTop = sql.IndexOf("select top ", StringComparison.Ordinal);
            var fimTop    = sql.IndexOf(" ", 11, StringComparison.Ordinal);

            top = ((indiceTop == 0) && (fimTop > 0))
                                ? Convert.ToInt32(sql.Substring(11, fimTop - 11))
                                : 0;
            var indiceWhere = sql.IndexOf("where", StringComparison.Ordinal);
            var condicao    = (indiceWhere > 0)
                                ? ConsultarCondicaoParaFiltragem(CommandText.Substring(indiceWhere + 5))
                                : string.Empty;
            var indiceOrderby = sql.IndexOf("order by", StringComparison.Ordinal);

            if ((indiceOrderby > 0) && (indiceOrderby > indiceWhere))
            {
                if (indiceWhere > 0)
                {
                    condicao = condicao.Substring(0, indiceOrderby - indiceWhere - 8 + 1 - 5 + 1);
                }
                view.Sort = CommandText.Substring(indiceOrderby + 8);
            }
            view.RowFilter = condicao;
            return(view);
        }
        private DataTable ConsultarTabelaComDadosVirtuais()
        {
            VerificarSeEhTabelaDeValidacaoDeExistencia();
            if (_bancoDeDadosVirtual.Tables.Count == 1)
            {
                return(_bancoDeDadosVirtual.Tables[0]);
            }
            var sql  = CommandText.ToLower();
            var from = sql.IndexOf("from", StringComparison.Ordinal);

            if (from == -1)
            {
                throw new NaoFoiPossivelDeterminarONomeDaTabelaFakeException();
            }
            sql = sql.Substring(from + 4).Trim();
            var corte = sql.IndexOf(sql.StartsWith("[") ? "]" : " ", StringComparison.Ordinal);

            if (corte == -1)
            {
                throw new NaoFoiPossivelDeterminarONomeDaTabelaFakeException();
            }
            var nome = sql.Substring(0, corte)
                       .Replace("[", string.Empty)
                       .Replace("]", string.Empty);

            if (!_bancoDeDadosVirtual.Tables.Contains(nome))
            {
                throw new NaoFoiPossivelDeterminarONomeDaTabelaFakeException();
            }
            return(_bancoDeDadosVirtual.Tables[nome]);
        }
        //Implementation
        public override void Execute()
        {
            //Make comand lower case
            string command = CommandText.ToLower();

            switch (command)
            {
            case "cut":
                DoCutCopyDelete(true, true);
                Controller.Clipboard.IsCopy = false;
                break;

            case "copy":
                DoCutCopyDelete(true, false);
                Controller.Clipboard.IsCopy = true;
                break;

            case "delete":
                DoCutCopyDelete(false, true);
                Controller.Refresh();
                break;

            case "paste":
                Controller.Suspend();
                Controller.SelectElements(false);
                Controller.Clipboard.Read();
                Controller.Clipboard.ResolveItems();
                DoPaste(Location);
                Controller.Clipboard.IsCopy = true;
                Controller.Resume();
                Controller.Refresh();
                break;
            }
        }
Esempio n. 4
0
        public IDataReader ExecuteReader()
        {
            var view      = ConsultarTabelaComDadosVirtuais().DefaultView;
            var sql       = CommandText.ToLower();
            var indiceTop = sql.IndexOf("select top ", StringComparison.Ordinal);
            var fimTop    = sql.IndexOf(" ", 11, StringComparison.Ordinal);
            var top       = ((indiceTop == 0) && (fimTop > 0))
                ? Convert.ToInt32(sql.Substring(11, fimTop - 11))
                : 0;
            var indiceWhere = sql.IndexOf("where", StringComparison.Ordinal);
            var condicao    = (indiceWhere > 0)
                                ? ConsultarCondicaoParaFiltragem(CommandText.Substring(indiceWhere + 5))
                                : string.Empty;
            var indiceOrderby = sql.IndexOf("order by", StringComparison.Ordinal);

            if ((indiceOrderby > 0) && (indiceOrderby > indiceWhere))
            {
                condicao  = condicao.Substring(0, indiceOrderby - indiceWhere - 8 + 1 - 5 + 1);
                view.Sort = CommandText.Substring(indiceOrderby + 8);
            }
            if (!string.IsNullOrEmpty(condicao))
            {
                view.RowFilter = condicao;
            }
            return(new DataReaderFake(view, top));
        }
        public virtual bool GetCommand()
        {
            //Make comand lower case
            string command = CommandText.ToLower();

            switch (command)
            {
            case "cut":
                return(Shapes.Count > 0 || Lines.Count > 0);

                break;

            case "copy":
                return(Shapes.Count > 0 || Lines.Count > 0);

                break;

            case "delete":
                return(Shapes.Count > 0 || Lines.Count > 0);

                break;

            case "paste":
                return(Controller.Clipboard.Elements != null);

                break;
            }

            return(false);
        }
Esempio n. 6
0
 public new H2DataReader ExecuteReader(CommandBehavior behavior)
 {
     // TODO check this : if (behavior != CommandBehavior.Default) { throw new NotSupportedException("Only CommandBehavior Default is supported for now."); }
     CheckConnection();
     EnsureStatment();
     try
     {
         var low   = CommandText.ToLower().Trim();
         var iSemi = low.IndexOf(';');
         if ((low.StartsWith("insert") || low.StartsWith("update")) && (iSemi < 0 || iSemi == low.Length - 1))
         {
             statement.executeUpdate();
             return(null);
         }
         else
         {
             return(new H2DataReader(connection, statement.executeQuery()));
         }
     }
     catch (org.h2.jdbc.JdbcSQLException ex)
     {
         ex.printStackTrace();
         throw new H2Exception(ex);
     }
 }
Esempio n. 7
0
        public object ExecuteScalar()
        {
            add(DatabaseAction.ExecuteScalarCommand(CommandText));

            if (CommandText == "error" || (CommandText.ToLower().Contains("count") && CommandText.ToLower().Contains("schemaversion") && !schemaTableExists))
            {
                ThrowError();
            }
            return(null);
        }
        public int ExecuteNonQuery(object[] source)
        {
            Connection.TraceListener.WriteLine("Executing: {0}", CommandText);
            if (Connection.ReadOnlyCaching)
            {
                var commandString = CommandText.ToLower();
                ReadOnlyQueryCache.CheckIfCacheNeedsClearing(Connection, commandString);
            }

            if (!Initialized)
            {
                Statement   = Prepare();
                Initialized = true;
            }

            var sqlitePlatform = Connection.Platform;

            //bind the values.
            if (source != null)
            {
                for (var i = 0; i < source.Length; i++)
                {
                    SQLiteCommand.BindParameter(sqlitePlatform.SQLiteApi, Statement, i + 1, source[i],
                                                Connection.StoreDateTimeAsTicks, Connection.Serializer);
                }
            }
            var r = sqlitePlatform.SQLiteApi.Step(Statement);

            if (r == Result.Done)
            {
                var rowsAffected = sqlitePlatform.SQLiteApi.Changes(Connection.Handle);
                sqlitePlatform.SQLiteApi.Reset(Statement);
                return(rowsAffected);
            }
            if (r == Result.Error)
            {
                var msg = sqlitePlatform.SQLiteApi.Errmsg16(Connection.Handle);
                sqlitePlatform.SQLiteApi.Reset(Statement);
                throw SQLiteException.New(r, msg);
            }
            if (r == Result.Constraint && sqlitePlatform.SQLiteApi.ExtendedErrCode(Connection.Handle) == ExtendedResult.ConstraintNotNull)
            {
                sqlitePlatform.SQLiteApi.Reset(Statement);
                throw NotNullConstraintViolationException.New(r, sqlitePlatform.SQLiteApi.Errmsg16(Connection.Handle));
            }
            sqlitePlatform.SQLiteApi.Reset(Statement);
            throw SQLiteException.New(r, r.ToString());
        }
Esempio n. 9
0
 /// <summary>
 /// Opens the connection if needed
 /// </summary>
 private void PrepareExecution()
 {
     if (!isPrepared)
     {
         isPrepared = true;
         if (Con.State != ConnectionState.Open)
         {
             Con.Open();
         }
         if (UseTransaction && _transaction == null)
         {
             cmd.Transaction = Transaction;
         }
     }
     #region Command logging, if a log file is specified
     string commandLog = CurrentCommandLogFile ?? CommandLogFile;
     if (!string.IsNullOrEmpty(commandLog))
     {
         if (SkipCommandLogFilters.Count > 0)
         {
             foreach (string filter in SkipCommandLogFilters)
             {
                 if (!string.IsNullOrEmpty(filter))
                 {
                     if (CommandText.ToLower().StartsWith(filter.ToLower()))
                     {
                         return;
                     }
                 }
             }
         }
         lock ( logFileLock ) {
             try {
                 StringBuilder sb = new StringBuilder(CommandText);
                 if (cmd.Parameters.Count > 0)
                 {
                     sb.Append(" ");
                 }
                 for (int i = 0; i < cmd.Parameters.Count; i++)
                 {
                     SQLiteParameter p = cmd.Parameters[i];
                     sb.Append(p.ParameterName);
                     sb.Append(" = ");
                     if (p.Value == DBNull.Value || p.Value == null)
                     {
                         sb.Append("NULL");
                     }
                     else
                     {
                         bool addQuote = false;
                         switch (p.DbType)
                         {
                         case DbType.String:
                         case DbType.StringFixedLength:
                         case DbType.AnsiStringFixedLength:
                         case DbType.AnsiString:
                         case DbType.Xml:
                         case DbType.Date:
                         case DbType.Time:
                         case DbType.DateTime2:
                         case DbType.Currency:
                             addQuote = true;
                             break;
                         }
                         if (addQuote)
                         {
                             sb.Append('\'');
                         }
                         string value = p.Value.ToString();
                         if (!addQuote && value.IndexOf(',') > -1)
                         {
                             value = value.Replace(',', '.');
                         }
                         sb.Append(value);
                         if (addQuote)
                         {
                             sb.Append('\'');
                         }
                     }
                     if ((i + 1) < cmd.Parameters.Count)
                     {
                         sb.Append(", ");
                     }
                 }
                 sb.Append(Environment.NewLine);
                 sb.Append("GO");
                 sb.Append(Environment.NewLine);
                 File.AppendAllText(commandLog, sb.ToString());
             } catch (Exception) {
             }
         }
     }
     #endregion
 }
Esempio n. 10
0
        private Boolean CheckFunctionNeedsColumnDefinitionList()
        {
            // If and only if a function returns "record" and has no OUT ("o" in proargmodes), INOUT ("b"), or TABLE
            // ("t") return arguments to characterize the result columns, we must provide a column definition list.
            // See http://pgfoundry.org/forum/forum.php?thread_id=1075&forum_id=519
            // We would use our Output and InputOutput parameters to construct that column definition list.  If we have
            // no such parameters, skip the check: we could only construct "AS ()", which yields a syntax error.

            // Updated after 0.99.3 to support the optional existence of a name qualifying schema and allow for case insensitivity
            // when the schema or procedure name do not contain a quote.
            // The hard-coded schema name 'public' was replaced with code that uses schema as a qualifier, only if it is provided.

            String returnRecordQuery;

            StringBuilder parameterTypes = new StringBuilder("");

            // Process parameters

            Boolean seenDef = false;

            foreach (NpgsqlParameter p in Parameters)
            {
                if ((p.Direction == ParameterDirection.Input) || (p.Direction == ParameterDirection.InputOutput))
                {
                    parameterTypes.Append(Connection.Connector.OidToNameMapping[p.TypeInfo.Name].OID.ToString() + " ");
                }

                if ((p.Direction == ParameterDirection.Output) || (p.Direction == ParameterDirection.InputOutput))
                {
                    seenDef = true;
                }
            }

            if (!seenDef)
            {
                return(false);
            }

            // Process schema name.

            String schemaName    = String.Empty;
            String procedureName = String.Empty;

            String[] fullName = CommandText.Split('.');

            String predicate = "prorettype = ( select oid from pg_type where typname = 'record' ) "
                               + "and proargtypes=:proargtypes and proname=:proname "
                               // proargmodes && array['o','b','t']::"char"[] performs just as well, but it requires PostgreSQL 8.2.
                               + "and ('o' = any (proargmodes) OR 'b' = any (proargmodes) OR 't' = any (proargmodes)) is not true";

            if (fullName.Length == 2)
            {
                returnRecordQuery =
                    "select count(*) > 0 from pg_proc p left join pg_namespace n on p.pronamespace = n.oid where " + predicate + " and n.nspname=:nspname";

                schemaName    = (fullName[0].IndexOf("\"") != -1) ? fullName[0] : fullName[0].ToLower();
                procedureName = (fullName[1].IndexOf("\"") != -1) ? fullName[1] : fullName[1].ToLower();
            }
            else
            {
                // Instead of defaulting don't use the nspname, as an alternative, query pg_proc and pg_namespace to try and determine the nspname.
                //schemaName = "public"; // This was removed after build 0.99.3 because the assumption that a function is in public is often incorrect.
                returnRecordQuery =
                    "select count(*) > 0 from pg_proc p where " + predicate;

                procedureName = (CommandText.IndexOf("\"") != -1) ? CommandText : CommandText.ToLower();
            }

            bool ret;

            using (NpgsqlCommand c = new NpgsqlCommand(returnRecordQuery, Connection))
            {
                c.Parameters.Add(new NpgsqlParameter("proargtypes", NpgsqlDbType.Oidvector));
                c.Parameters.Add(new NpgsqlParameter("proname", NpgsqlDbType.Name));

                c.Parameters[0].Value = parameterTypes.ToString();
                c.Parameters[1].Value = procedureName;

                if (schemaName != null && schemaName.Length > 0)
                {
                    c.Parameters.Add(new NpgsqlParameter("nspname", NpgsqlDbType.Name));
                    c.Parameters[2].Value = schemaName;
                }

                ret = (Boolean)c.ExecuteScalar();
            }

            return(ret);
        }
Esempio n. 11
0
        //Implementation
        public override void Execute()
        {
            if (Labels == null)
            {
                return;
            }

            //Create the momentos of the current labels
            _momentos = new List <LabelMomento>();

            //Loop through and add a momento for each label
            foreach (Label label in _labels)
            {
                LabelMomento momento = new LabelMomento(label);
                _momentos.Add(momento);
            }

            //Make comand lower case
            string command = CommandText.ToLower();

            switch (command)
            {
            case "bold":
                Controller.Suspend();
                DoCommandText(true, false, false, false);
                Controller.Resume();
                Controller.Invalidate();
                break;

            case "italic":
                Controller.Suspend();
                DoCommandText(false, true, false, false);
                Controller.Resume();
                Controller.Invalidate();
                break;

            case "strikeout":
                Controller.Suspend();
                DoCommandText(false, false, true, false);
                Controller.Resume();
                Controller.Invalidate();
                break;

            case "underline":
                Controller.Suspend();
                DoCommandText(false, false, false, true);
                Controller.Resume();
                Controller.Invalidate();
                break;

            case "align left":
                Controller.Suspend();
                DoCommandAlign(true, false, false);
                Controller.Resume();
                Controller.Invalidate();
                break;

            case "align center":
                Controller.Suspend();
                DoCommandAlign(false, true, false);
                Controller.Resume();
                Controller.Invalidate();
                break;

            case "align right":
                Controller.Suspend();
                DoCommandAlign(false, false, true);
                Controller.Resume();
                Controller.Invalidate();
                break;

            case "align top":
                Controller.Suspend();
                DoCommandVerticalAlign(true, false, false);
                Controller.Resume();
                Controller.Invalidate();
                break;

            case "align middle":
                Controller.Suspend();
                DoCommandVerticalAlign(false, true, false);
                Controller.Resume();
                Controller.Invalidate();
                break;

            case "align bottom":
                Controller.Suspend();
                DoCommandVerticalAlign(false, false, true);
                Controller.Resume();
                Controller.Invalidate();
                break;

            case "font":
                Controller.Suspend();
                DoCommandFont(Controller.Model.SelectedShapes(), CommandValue);
                Controller.Resume();
                Controller.Invalidate();
                break;

            case "font size":
                Controller.Suspend();
                DoCommandFontSize(Controller.Model.SelectedShapes(), CommandValue);
                Controller.Resume();
                Controller.Invalidate();
                break;
            }
        }