Esempio n. 1
0
 public int buildSQL(DatabaseConnection dbConn, int index, StringBuilder b)
 {
     if (!string.IsNullOrEmpty(searchFieldName) && !string.IsNullOrEmpty(selectQueryOrItemList))
     {
         b.Append(searchFieldName).Append(" IN (").Append(selectQueryOrItemList);
         if (filter != null)
         {
             b.Append(" ").Append(filter.getWhereClause(dbConn, true, index, out index));
         }
         b.Append(")");
     }
     return(index);
 }
Esempio n. 2
0
        public int buildSQL(DatabaseConnection dbConn, int index, StringBuilder b)
        {
            if (notExist)
            {
                b.Append(" NOT");
            }
            b.Append(" EXISTS (SELECT ").Append(selectFieldList).Append(" FROM ").Append(tableName);
            int out_index = 0;

            if (filter != null)
            {
                b.Append(filter.getWhereClause(dbConn, true, index, out out_index));
                b.Append(filter.getGroupCluase());
            }
            b.Append(")");

            return(out_index);
        }
Esempio n. 3
0
        public DbCommand CreateDeleteCommand(string DeleteQueryHeader, DBFilter dbFilter)
        {
            int commandIndex  = 1;
            int buildSQLIndex = 1;

            string    query   = DeleteQueryHeader;
            DbCommand command = CreateCommand();

            command.CommandType = CommandType.Text;

            if (dbFilter != null)
            {
                query += dbFilter.getWhereClause(this, false, buildSQLIndex, out buildSQLIndex);
                dbFilter.setParams(commandIndex, command);
            }
            command.CommandText = query;

            return(command);
        }
Esempio n. 4
0
        public DbCommand CreateSelectCommand(string SelectQueryWithoutConstraint, DBFilter dbFilter, ListInfo info)
        {
            int commandIndex  = 1;
            int buildSQLIndex = 1;

            string query = SelectQueryWithoutConstraint;

            DbCommand command = CreateCommand();

            command.CommandType = CommandType.Text;

            if (dbFilter != null)
            {
                query += dbFilter.getWhereClause(this, false, buildSQLIndex, out buildSQLIndex);
                query += dbFilter.getGroupCluase();
                query += dbFilter.getOrderClause(info);
                dbFilter.setParams(commandIndex, command);
            }
            command.CommandText = query;


            return(command);
        }
Esempio n. 5
0
        //public DbCommand CreateSelectCommand(string FieldList, string TableList, DBFilter dbFilter)
        //{

        //    string query = "SELECT " + FieldList + " FROM " + TableList;
        //    return CreateSelectCommand(query, dbFilter, null);
        //}

        private DbCommand CreateUpdateCommand(string tablename, DBObject obj, ICollection <DBField> dbFieldList, DBFilter dbFilter)
        {
            int commandIndex  = 1;
            int buildSQLIndex = 1;

            DbCommand command = CreateCommand();

            command.CommandType = CommandType.Text;

            string updateField = string.Empty;

            foreach (DBField dbField in dbFieldList)
            {
                if (!dbField.isAuto)
                {
                    if (obj.isModified(dbField.name))
                    {
                        object value = dbField.property.GetValue(obj, null);
                        if (value is string)
                        {
                            value = ((string)value).Trim();
                        }
                        if (dbField.transcoder != null)
                        {
                            value = dbField.transcoder.toDB(value);
                        }


                        string fieldParameterName = getQueryValueParameterName(buildSQLIndex.ToString());
                        buildSQLIndex++;
                        string valueParameterName = "@" + commandIndex++;
                        string assignValue        = dbField.columnName + " = " + fieldParameterName;

                        if (updateField.Equals(string.Empty))
                        {
                            updateField = " SET " + assignValue;
                        }
                        else
                        {
                            updateField += ", " + assignValue;
                        }

                        SetUpdateCommandDBParameter(command, valueParameterName, value);
                    }
                }
            }
            if (!string.IsNullOrEmpty(updateField))
            {
                string query = "UPDATE " + tablename + updateField;

                if (dbFilter != null)
                {
                    query += dbFilter.getWhereClause(this, false, buildSQLIndex, out buildSQLIndex);
                    dbFilter.setParams(commandIndex, command);
                }
                command.CommandText = query;

                return(command);
            }
            else
            {
                return(null);
            }
        }