/// <summary> /// 获取指定的表架构生成的SQL(Create Table)语句 /// </summary> internal static string CreateTableSql(string tableName, MDataColumn columns, DalType dalType, string version) { switch (dalType) { case DalType.Txt: case DalType.Xml: return(columns.ToJson(true)); default: string createSql = string.Empty; createSql = "CREATE TABLE " + SqlFormat.Keyword(tableName, dalType) + " \n("; //读取主键的个数,如果是联合主键,则不设置主键。 List <MCellStruct> primaryKeyList = new List <MCellStruct>(); foreach (MCellStruct column in columns) { if (column.IsPrimaryKey) { primaryKeyList.Add(column); } } foreach (MCellStruct column in columns) { createSql += "\n " + GetKey(column, dalType, ref primaryKeyList, version); } if (primaryKeyList.Count > 0) { createSql += GetUnionPrimaryKey(dalType, primaryKeyList); } createSql = createSql.TrimEnd(',') + " \n)"; // createSql += GetSuffix(dalType); if (dalType == DalType.MySql && createSql.IndexOf("CURRENT_TIMESTAMP") != createSql.LastIndexOf("CURRENT_TIMESTAMP")) { createSql = createSql.Replace("Default CURRENT_TIMESTAMP", string.Empty); //mysql不允许存在两个以上的CURRENT_TIMESTAMP。 } primaryKeyList.Clear(); return(createSql); } }
/// <summary> /// ��ȡָ���ı�ܹ����ɵ�SQL(Create Table)��� /// </summary> internal static string CreateTableSql(string tableName, MDataColumn columns, DalType dalType, string version) { switch (dalType) { case DalType.Txt: case DalType.Xml: return columns.ToJson(true); default: string createSql = string.Empty; createSql = "CREATE TABLE " + SqlFormat.Keyword(tableName, dalType) + " \n("; //��ȡ�����ĸ�������������������������������� List<MCellStruct> primaryKeyList = new List<MCellStruct>(); foreach (MCellStruct column in columns) { if (column.IsPrimaryKey) { primaryKeyList.Add(column); } } foreach (MCellStruct column in columns) { createSql += "\n " + GetKey(column, dalType, ref primaryKeyList, version); } if (primaryKeyList.Count > 0) { createSql += GetUnionPrimaryKey(dalType, primaryKeyList); } createSql = createSql.TrimEnd(',') + " \n)"; // createSql += GetSuffix(dalType); if (dalType == DalType.MySql && createSql.IndexOf("CURRENT_TIMESTAMP") != createSql.LastIndexOf("CURRENT_TIMESTAMP")) { createSql = createSql.Replace("Default CURRENT_TIMESTAMP", string.Empty);//mysql����������������ϵ�CURRENT_TIMESTAMP�� } primaryKeyList.Clear(); return createSql; } }
private void btnToJson_Click(object sender, EventArgs e) { rtxtMsg.Text = mdc.ToJson(true); }