コード例 #1
0
ファイル: XSql.cs プロジェクト: foxbill/xbase-2018.01
        public string GetInsertCommand()
        {
            string tableName = GetFrom();
            string insertCmd = "INSERT INTO " + tableName + " (";

            string values = "";

            DatabaseAdmin db = DatabaseAdmin.getInstance(schema.ConnectionName);

            foreach (FieldSchema fldsch in schema.Fields)
            {
                if (!fldsch.ReadOnly && !db.isIdentityField(tableName, fldsch.Id) && !db.isRowGuidField(tableName, fldsch.Id))
                {
                    insertCmd += " [" + fldsch.Id + "]" + XTableSchemaConst.FieldSplitor;
                    values    += "@" + fldsch.Id + XTableSchemaConst.FieldSplitor;
                }
            }


            values = values.Remove(values.LastIndexOf(XTableSchemaConst.FieldSplitor));

            insertCmd  = insertCmd.Remove(insertCmd.Length - 1);
            insertCmd += ")";
            insertCmd += " VALUES (" + values + ")";

            if (schema.PrimaryKeys != null && schema.PrimaryKeys.Count > 0)
            {
                List <string> pks = schema.PrimaryKeys;
                string        id  = "";
                foreach (string fieldName in pks)
                {
                    if (db.isIdentityField(tableName, fieldName))
                    {
                        id = fieldName;
                        break;
                    }
                }
                if (!string.IsNullOrEmpty(id))
                {
                    insertCmd += ";SELECT * FROM " + tableName + " WHERE [" + id + "]=SCOPE_IDENTITY()";
                }
            }
            // db.Close();
            return(insertCmd);
        }
コード例 #2
0
ファイル: XSql.cs プロジェクト: foxbill/xbase-2018.01
        public string GetUpdateCommand()
        {
            DatabaseAdmin db = DatabaseAdmin.getInstance(schema.ConnectionName);

            List <string> pks = schema.PrimaryKeys;

            if (pks == null || pks.Count < 1)
            {
                throw new E_SQLBuilder_NoPrimaryKey();
            }

            string tableName = GetFrom();
            string update    = "UPDATE " + tableName + " SET ";


            foreach (FieldSchema fldsch in schema.Fields)
            {
                if (!fldsch.ReadOnly && !db.isIdentityField(tableName, fldsch.Id) && !db.isRowGuidField(tableName, fldsch.Id))
                {
                    update += " [" + fldsch.Id + "]=@" + fldsch.Id + ",";
                }
            }

            update = update.Remove(update.Length - 1);

            update += " WHERE ";

            foreach (string pk in pks)
            {
                update += " [" + pk + "]=@" + OLD_VERSION_PIX + pk + " And ";
            }

            update = update.Remove(update.LastIndexOf(" And "));

            return(update);
        }