Esempio n. 1
0
        public override SqlString OnPrepareStatement(SqlString sql)
        {
            var info = new CatalogSchemaLocator();

            this.locatorVisitor(info);

            if (this.interceptCatalog)
            {
                if (info.Catalog.IsEmpty())
                {
                    throw new ArgumentException("Catalog was not supplied");
                }

                sql = sql.Replace(this.CatalogPlaceHolder, info.Catalog);
            }
            if (this.interceptSchema)
            {
                // TODO: what about querying all schemas?  might screw up nhibernate due to duplicate keys going into 1st level cache
                if (info.Schema.IsEmpty())
                {
                    throw new ArgumentException("Schema was not supplied");
                }

                sql = sql.Replace(this.SchemaPlaceHolder, info.Schema);
            }
            return(base.OnPrepareStatement(sql));
        }
Esempio n. 2
0
        public void Replace()
        {
            SqlString sql =
                new SqlString(
                    new object[] { "select ", "from table ", "where a = ", Parameter.Placeholder, " and c = ", Parameter.Placeholder });
            SqlString replacedSql = sql.Replace("table", "replacedTable");

            Assert.AreEqual(sql.ToString().Replace("table", "replacedTable"), replacedSql.ToString());

            replacedSql = sql.Replace("not found", "not in here");
            Assert.AreEqual(sql.ToString().Replace("not found", "not in here"), replacedSql.ToString(), "replace no found string");

            replacedSql = sql.Replace("le", "LE");
            Assert.AreEqual(sql.ToString().Replace("le", "LE"), replacedSql.ToString(), "multi-match replace");
        }
        public override SqlString OnPrepareStatement(SqlString sql)
        {
            Match  match      = Regex.Match(sql.ToString());
            String tableName  = match.Groups[1].Value;
            String tableAlias = match.Groups[2].Value;

            sql = sql.Substring(match.Groups[2].Index);
            sql = sql.Replace(tableAlias, tableName);
            sql = sql.Insert(0, "delete from ");

            Int32 orderByIndex = sql.IndexOfCaseInsensitive(" order by ");

            if (orderByIndex > 0)
            {
                sql = sql.Substring(0, orderByIndex);
            }

            int limitIndex = sql.IndexOfCaseInsensitive(" limit ");

            if (limitIndex > 0)
            {
                sql = sql.Substring(0, limitIndex);
            }

            return(sql);
        }
Esempio n. 4
0
        public void Replace_Test()
        {
            var query    = new SqlString("Hello World");
            var newQuery = query.Replace("World", "Belgium");

            Assert.AreEqual("Hello Belgium", query);
            Assert.AreEqual("Hello Belgium", newQuery);
        }
Esempio n. 5
0
        public override SqlString OnPrepareStatement(SqlString sql)
        {
            // If a recompile comment string was found - add an RECOMPILE option at the end of the statement
            if (sql.ToString().Contains(QueryHintRecompileCommentString))
            {
                return(sql.Replace(";\r\n", _queryHintOptionRecompileString));
            }

            return(sql);
        }
Esempio n. 6
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
        {
            var parameters = _sql.GetParameters().ToList();
            var paramPos   = 0;

            for (int i = 0; i < _typedValues.Length; i++)
            {
                var controlledParameters = criteriaQuery.NewQueryParameter(_typedValues[i]);
                foreach (Parameter parameter in controlledParameters)
                {
                    parameters[paramPos++].BackTrack = parameter.BackTrack;
                }
            }
            return(_sql.Replace("{alias}", criteriaQuery.GetSQLAlias(criteria)));
        }
Esempio n. 7
0
 public void OnGeneratePhpCode(StringCollection pageCode, StringCollection methods, StringCollection requestExecutes)
 {
     if (IsValid && UseDataFromDatabase)
     {
         StringBuilder sb = new StringBuilder();
         sb.Append("function ");
         sb.Append(TableName);
         sb.Append("()\r\n");
         sb.Append("{\r\n");
         sb.Append("  $sql = '");
         sb.Append(SqlString.Replace("'", "\\'"));
         sb.Append("';\r\n");
         sb.Append("  $tbl = $this->AddDataTable('");
         sb.Append(TableName);
         sb.Append("');\r\n");
         sb.Append("  $ps = array();\r\n");
         sb.Append("  $msql = new JsonSourceMySql();\r\n");
         sb.Append("  $msql->SetCredential($this->");
         sb.Append(ServerCodeutility.GetPhpMySqlConnectionName(this.ConnectionID));
         sb.Append(");\r\n");
         sb.Append("  $msql->SetDebug($this->DEBUG);\r\n");
         sb.Append("  $msql->GetData($tbl,$sql,$ps);\r\n");
         //
         sb.Append("}\r\n");
         //
         methods.Add(sb.ToString());
         //
         sb = new StringBuilder();
         sb.Append("if($method == '");
         sb.Append(TableName);
         sb.Append("') $this->");
         sb.Append(TableName);
         sb.Append("();\r\n");
         requestExecutes.Add(sb.ToString());
     }
 }
Esempio n. 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="persistentClass"></param>
 /// <param name="alias"></param>
 /// <returns></returns>
 public override SqlString ToSqlString(ISessionFactoryImplementor factory, System.Type persistentClass, string alias, IDictionary aliasClasses)
 {
     return(_sql.Replace("{alias}", alias));
 }
Esempio n. 9
0
 public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
 {
     return(_sql.Replace("{alias}", criteriaQuery.GetSQLAlias(criteria)));
 }
 /// <summary>
 /// MS Access and SQL Server support limit. This implementation has been made according the MS Access syntax
 /// </summary>
 /// <param name="querySqlString">The original query</param>
 /// <param name="offset">Specifies the number of rows to skip, before starting to return rows from the query expression.</param>
 /// <param name="limit">Is used to limit the number of results returned in a SQL statement</param>
 /// <returns>Processed query</returns>
 public override SqlString GetLimitString(SqlString querySqlString, int offset, int limit)
 {
     return(querySqlString.Replace("select", string.Format("select top {0}", limit)));
 }