Exemple #1
0
        public static string GetUpdateSql(TableInfo tableInfo)
        {
            StringBuilder sbBody = new StringBuilder();


            foreach (String key in tableInfo.Columns.Keys)
            {
                Object value = tableInfo.Columns[key];
                if (!string.IsNullOrEmpty(key.Trim()) && value != null)
                {
                    string nKey = DbKeywords.FormatColumnName(key.Trim());
                    sbBody.Append(nKey).Append("=").Append(AdoHelper.DbParmChar + key).Append(",");
                }
            }

            if (sbBody.Length > 0)
            {
                sbBody.Remove(sbBody.ToString().Length - 1, 1);
            }

            tableInfo.Columns.Put(tableInfo.Id.Key, tableInfo.Id.Value);

            string strSql = "update {0} set {1} where {2} =" + AdoHelper.DbParmChar + tableInfo.Id.Key;

            strSql = string.Format(strSql, tableInfo.TableName, sbBody.ToString(), tableInfo.Id.Key);

            return(strSql);
        }
Exemple #2
0
        public static string GetFindByIdSql(TableInfo tableInfo)
        {
            StringBuilder sbColumns = new StringBuilder();

            if (tableInfo.Columns.ContainsKey(tableInfo.Id.Key))
            {
                tableInfo.Columns[tableInfo.Id.Key] = tableInfo.Id.Value;
            }
            else
            {
                tableInfo.Columns.Put(tableInfo.Id.Key, tableInfo.Id.Value);
            }

            foreach (String key in tableInfo.Columns.Keys)
            {
                string nKey = DbKeywords.FormatColumnName(key.Trim());
                sbColumns.Append(nKey).Append(",");
            }

            if (sbColumns.Length > 0)
            {
                sbColumns.Remove(sbColumns.ToString().Length - 1, 1);
            }

            string strSql = "SELECT {0} FROM {1} WHERE {2} = " + AdoHelper.DbParmChar + "{2}";

            strSql = string.Format(strSql, sbColumns.ToString(), tableInfo.TableName, tableInfo.Id.Key);

            return(strSql);
        }
Exemple #3
0
        public static string GetFindSql(TableInfo tableInfo, DbCondition condition)
        {
            StringBuilder sbColumns = new StringBuilder();

            tableInfo.Columns.Put(tableInfo.Id.Key, tableInfo.Id.Value);
            foreach (String key in tableInfo.Columns.Keys)
            {
                string nKey = DbKeywords.FormatColumnName(key.Trim());
                sbColumns.Append(nKey).Append(",");
            }

            if (sbColumns.Length > 0)
            {
                sbColumns.Remove(sbColumns.ToString().Length - 1, 1);
            }

            string strSql = String.Empty;

            if (String.IsNullOrEmpty(condition.queryString))
            {
                strSql  = "SELECT {0} FROM {1}";
                strSql  = string.Format(strSql, sbColumns.ToString(), tableInfo.TableName);
                strSql += condition.ToString();
            }
            else
            {
                strSql = condition.ToString();
            }

            strSql = strSql.ToUpper();

            return(strSql);
        }
Exemple #4
0
        public static string GetInsertSql(TableInfo tableInfo)
        {
            StringBuilder sbColumns = new StringBuilder();
            StringBuilder sbValues  = new StringBuilder();

            if (tableInfo.Strategy != GenerationType.INDENTITY)
            {
                if (tableInfo.Strategy == GenerationType.GUID && tableInfo.Id.Value == null)
                {
                    tableInfo.Id.Value = Guid.NewGuid().ToString();
                }

                if (tableInfo.Id.Value != null)
                {
                    tableInfo.Columns.Put(tableInfo.Id.Key, tableInfo.Id.Value);
                }
            }

            foreach (String key in tableInfo.Columns.Keys)
            {
                Object value = tableInfo.Columns[key];
                if (!string.IsNullOrEmpty(key.Trim()) && value != null)
                {
                    string nKey = DbKeywords.FormatColumnName(key.Trim());
                    sbColumns.Append(nKey).Append(",");
                    sbValues.Append(AdoHelper.DbParmChar).Append(key).Append(",");
                }
            }

            if (sbColumns.Length > 0 && sbValues.Length > 0)
            {
                sbColumns.Remove(sbColumns.ToString().Length - 1, 1);
                sbValues.Remove(sbValues.ToString().Length - 1, 1);
            }

            string strSql = "INSERT INTO {0}({1}) VALUES({2})";

            strSql = string.Format(strSql, tableInfo.TableName, sbColumns.ToString(), sbValues.ToString());

            if (AdoHelper.DbType == DatabaseType.SQLSERVER || AdoHelper.DbType == DatabaseType.MYSQL)
            {
                string autoSql = EntityHelper.GetAutoSql();
                strSql = strSql + autoSql;
            }

            return(strSql);
        }
Exemple #5
0
        public static string GetFindCountSql(TableInfo tableInfo)
        {
            StringBuilder sbColumns = new StringBuilder();

            string strSql = "SELECT COUNT(0) FROM {1} ";

            strSql = string.Format(strSql, sbColumns.ToString(), tableInfo.TableName);

            foreach (String key in tableInfo.Columns.Keys)
            {
                string nKey = DbKeywords.FormatColumnName(key.Trim());
                sbColumns.Append(nKey).Append("=").Append(AdoHelper.DbParmChar).Append(key);
            }

            if (sbColumns.Length > 0)
            {
                strSql += " WHERE " + sbColumns.ToString();
            }

            return(strSql);
        }
Exemple #6
0
        public static string GetFindAllSql(TableInfo tableInfo)
        {
            StringBuilder sbColumns = new StringBuilder();

            tableInfo.Columns.Put(tableInfo.Id.Key, tableInfo.Id.Value);
            foreach (String key in tableInfo.Columns.Keys)
            {
                string nKey = DbKeywords.FormatColumnName(key.Trim());
                sbColumns.Append(nKey).Append(",");
            }

            if (sbColumns.Length > 0)
            {
                sbColumns.Remove(sbColumns.ToString().Length - 1, 1);
            }

            string strSql = "SELECT {0} FROM {1}";

            strSql = string.Format(strSql, sbColumns.ToString(), tableInfo.TableName);

            return(strSql);
        }