Ejemplo n.º 1
0
        // Allow the User to Get the SQL Statement Generated.
        public string GetSQL()
        {
            try
            {
                // Validate if the User can proceed with the delete.
                // Attach the Main Statement.
                StringBuilder sqlBuilder = new StringBuilder();
                sqlBuilder.Append("DELETE FROM ")
                .Append(tableName);

                // Add the Where Clauses.
                if (whereClauseBuilder.Length > 0)
                {
                    sqlBuilder.Append(" WHERE ")
                    .Append(whereClauseBuilder);

                    if (CloudDB.IsSyncable(tableName))
                    {
                        string rlsWhere = cdb.RLSWhere(CloudDB.QueryType.DELETE);
                        if (rlsWhere.Trim().Length > 0)
                        {
                            sqlBuilder.Append(" AND ")
                            .Append(rlsWhere);
                        }
                    }
                }
                else if (CloudDB.IsSyncable(tableName))
                {
                    string rlsWhere = cdb.RLSWhere(CloudDB.QueryType.DELETE);
                    if (rlsWhere.Trim().Length > 0)
                    {
                        sqlBuilder.Append(" WHERE ")
                        .Append(rlsWhere);
                    }
                }

                return(sqlBuilder.ToString());
            }
            catch (Exception e)
            {
                // There was an Error.
                return("Error : " + e.Message);
            }
        }
Ejemplo n.º 2
0
        // Here we generate the SQL Statement for the User.
        private string GetSQL()
        {
            try
            {
                // Here we generate the SQL Statement.
                // Attach the Main Select statement.
                StringBuilder sqlBuilder = new StringBuilder();
                if (columnNameBuilder.Length == 0)
                {
                    columnNameBuilder.Append(" * ");
                }
                sqlBuilder.Append("SELECT ")
                .Append(columnNameBuilder)
                .Append(" FROM ")
                .Append(tableName);

                // Add the Join.
                if (joinsBuilder.Length > 0)
                {
                    sqlBuilder.Append(joinsBuilder);
                }

                // Add the Where Clauses.
                if (whereClauseBuilder.Length > 0)
                {
                    sqlBuilder.Append(" WHERE ")
                    .Append(whereClauseBuilder);
                    if (CloudDB.IsSyncable(tableName))
                    {
                        if (joinTables.Count > 0)
                        {
                            // There are tables that are joint.
                            string rlsWhere = cdb.RLSWhere(CloudDB.QueryType.SELECT, tableName);
                            if (rlsWhere.Trim().Length > 0)
                            {
                                sqlBuilder.Append(" AND ")
                                .Append(rlsWhere);
                            }

                            // Now Lets handle the Tables being Joint.
                            for (int joinTbIndex = 0; joinTbIndex < joinTables.Count; joinTbIndex++)
                            {
                                rlsWhere = cdb.RLSWhere(CloudDB.QueryType.SELECT, joinTables[joinTbIndex]);
                                if (rlsWhere.Trim().Length > 0)
                                {
                                    sqlBuilder.Append(" AND ")
                                    .Append(rlsWhere);
                                }
                            }
                        }
                        else
                        {
                            // No Tables have been Joined.
                            string rlsWhere = cdb.RLSWhere(CloudDB.QueryType.SELECT);
                            if (rlsWhere.Trim().Length > 0)
                            {
                                sqlBuilder.Append(" AND ")
                                .Append(rlsWhere);
                            }
                        }
                    }
                }
                else if (CloudDB.IsSyncable(tableName))
                {
                    if (joinTables.Count > 0)
                    {
                        // There are Tables that are Joint.
                        string rlsWhere = cdb.RLSWhere(CloudDB.QueryType.SELECT, tableName);
                        if (rlsWhere.Trim().Length > 0)
                        {
                            sqlBuilder.Append(" WHERE ")
                            .Append(rlsWhere);
                        }

                        // Now Lets Handle the Tables being Joint.
                        for (int joinTbIndex = 0; joinTbIndex < joinTables.Count; joinTbIndex++)
                        {
                            rlsWhere = cdb.RLSWhere(CloudDB.QueryType.SELECT, joinTables[joinTbIndex]);
                            if (rlsWhere.Trim().Length > 0)
                            {
                                sqlBuilder.Append(" AND ")
                                .Append(rlsWhere);
                            }
                        }
                    }
                    else
                    {
                        // There are Tables Being Joint.
                        string rlsWhere = cdb.RLSWhere(CloudDB.QueryType.SELECT);
                        if (rlsWhere.Trim().Length > 0)
                        {
                            sqlBuilder.Append(" WHERE ")
                            .Append(rlsWhere);
                        }
                    }
                }

                // Add the Order by Clause.
                if (orderByClauseBuilder.Length > 0)
                {
                    sqlBuilder.Append(" ORDER BY ")
                    .Append(orderByClauseBuilder);
                }

                return(sqlBuilder.ToString());
            }
            catch (Exception e)
            {
                // There was an Error.
                return("Err : " + e.Message);
            }
        }