Ejemplo n.º 1
0
        private void AddColumns()
        {
            DataTable dt = SQLSvrDbi.GetTableColumns(SchemaName, TableName);

            if (dt != null & dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    DbField field = new DbField();

                    String colName = row["ColumnName"].ToString().Trim();

                    if (GemFireXDDbi.IsReservedWord(colName))
                    {
                        colName = String.Format("\"{0}\"", colName);
                    }
                    if (colName.Contains(" "))
                    {
                        colName = colName.Replace(" ", "_");
                    }

                    field.FieldName = colName;

                    if (!String.IsNullOrEmpty(row["CharMaxLength"].ToString()))
                    {
                        field.Length = Convert.ToInt32(row["CharMaxLength"].ToString());
                    }

                    field.FieldType = DbTypeMap.GetGFXDTypeFromSqlType(row["DataType"].ToString());

                    if (row["IsNullable"].ToString().Trim() == "YES")
                    {
                        field.IsNullable = true;
                    }

                    Columns.Add(field);
                }
            }
        }
Ejemplo n.º 2
0
        public String GetCreateTableSql()
        {
            StringBuilder sql = new StringBuilder();

            sql.Append("CREATE TABLE ");
            sql.AppendFormat("{0} (", TableFullName);

            foreach (DbField field in Columns)
            {
                sql.AppendFormat("{0} {1} {2}, ",
                                 field.FieldName, DbTypeMap.GetJdbcTypeFromGFXDType(field.FieldType, field.Length),
                                 (field.IsNullable ? String.Empty : "NOT NULL"));
            }

            foreach (String constraint in Constraints)
            {
                sql.AppendFormat("{0}, ", constraint);
            }

            sql = sql.Remove(sql.Length - 2, 1).Append(") ");

            return(sql.ToString());
        }