SQL-MAP是PDF.NET(PWMIS数据开发框架)具有特色的开发技术,它可以将SQL语句映射成DAL代码,而且能够做到无需IDAL和DalFactory自动切换数据库到另外一个数据库系统,比如SqlServer切换到Oralcle,有关SQL-MAP的规范请看这里,为什么要使用这种技术,请看“抽象SQL(参数化)查询
”。

           刚刚发现了一款超级好的xml相关的编辑工具Liquid XML
Studio,带图形编辑界面,非常好用,特别是在编辑xsd和xslt的时候.

   
从上面的规范看到,要手写一个SQL-MAP文件还是比较复杂,虽然框架提供了SQL-MAP配置文件管理器,但它主要适用于新手使用,用起来效率不是很高,这个时候就需要有一个可以只能提示XML文件编写的东西了,这就是SqlMap.xsd,下面贴出该文件的最新完整内容:

           图片 1

 

图片 2

图片 3图片 4SqlMap.XSD

图片 5图片 6XSD Code

<?xml version=”1.0″ encoding=”utf-8″ ?>
<xs:schema attributeFormDefault=”unqualified” elementFormDefault=”qualified” xmlns:xs=”http://www.w3.org/2001/XMLSchema"&gt;
    <xs:simpleType name=”enumCmdType” >
        <xs:restriction base =”xs:string”>
            <xs:enumeration value =”Text”></xs:enumeration>
            <xs:enumeration value =”StoredProcedure”></xs:enumeration>
            <xs:enumeration value =”Table”></xs:enumeration>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name=”enumResultClass” >
        <xs:restriction base =”xs:string”>
            <xs:enumeration value =”ValueType”></xs:enumeration>
            <xs:enumeration value =”DataSet”></xs:enumeration>
            <xs:enumeration value =”EntityObject”></xs:enumeration>
            <xs:enumeration value =”EntityList”></xs:enumeration>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name=”enumScriptType” >
        <xs:restriction base =”xs:string”>
            <xs:enumeration value =”Access”></xs:enumeration>
            <xs:enumeration value =”SqlServer”></xs:enumeration>
            <xs:enumeration value =”SqlServerCe”></xs:enumeration>
            <xs:enumeration value =”Oracle”></xs:enumeration>
            <xs:enumeration value =”DB2″></xs:enumeration>
            <xs:enumeration value =”Sysbase”></xs:enumeration>
            <xs:enumeration value =”MySql”></xs:enumeration>
            <xs:enumeration value =”SQLite”></xs:enumeration>
            <xs:enumeration value =”PostgreSQL”></xs:enumeration>
            <xs:enumeration value =”UNKNOWN”></xs:enumeration>
        </xs:restriction>
    </xs:simpleType>
    <xs:element name=”SqlMap”>
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs=”unbounded” name=”Script”>
                    <xs:complexType>
                         <xs:sequence>
                            <xs:element maxOccurs=”unbounded” name=”CommandClass”>
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:choice maxOccurs=”unbounded”>
                                            <xs:element maxOccurs=”unbounded” name=”Select”>
                                                <xs:complexType>
                                                    <xs:simpleContent>
                                                        <xs:extension base=”xs:string”>
                                                            <xs:attribute name=”CommandName” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”CommandType” type=”enumCmdType” use=”required” />
                                                            <xs:attribute name=”Method” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”Description” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”ResultClass” type=”enumResultClass” use=”optional”  default=”DataSet”/>
                                                            <xs:attribute name=”ResultMap” type=”xs:string” use=”optional” />
                                                            <xs:attribute name=”SqlPage” type=”xs:string” use=”optional” default=”False”/>
                                                        </xs:extension>
                                                    </xs:simpleContent>
                                                </xs:complexType>
                                            </xs:element>
                                            <xs:element name=”Insert”>
                                                <xs:complexType>
                                                    <xs:simpleContent>
                                                        <xs:extension base=”xs:string”>
                                                            <xs:attribute name=”CommandName” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”CommandType” type=”enumCmdType” use=”required” />
                                                            <xs:attribute name=”Method” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”Description” type=”xs:string” use=”required” />
                                                        </xs:extension>
                                                    </xs:simpleContent>
                                                </xs:complexType>
                                            </xs:element>
                                            <xs:element name=”Update”>
                                                <xs:complexType>
                                                    <xs:simpleContent>
                                                        <xs:extension base=”xs:string”>
                                                            <xs:attribute name=”CommandName” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”CommandType” type=”enumCmdType” use=”required” />
                                                            <xs:attribute name=”Method” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”Description” type=”xs:string” use=”required” />
                                                        </xs:extension>
                                                    </xs:simpleContent>
                                                </xs:complexType>
                                            </xs:element>
                                            <xs:element name=”Delete”>
                                                <xs:complexType>
                                                    <xs:simpleContent>
                                                        <xs:extension base=”xs:string”>
                                                            <xs:attribute name=”CommandName” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”CommandType” type=”enumCmdType” use=”required” />
                                                            <xs:attribute name=”Method” type=”xs:string” use=”required” />
                                                            <xs:attribute name=”Description” type=”xs:string” use=”required” />
                                                        </xs:extension>
                                                    </xs:simpleContent>
                                                </xs:complexType>
                                            </xs:element>
                                        </xs:choice>
                                    </xs:sequence>
                                    <xs:attribute name=”Name” type=”xs:string” use=”required” />
                                    <xs:attribute name=”Class” type=”xs:string” use=”required” />
                                    <xs:attribute name=”Interface” type=”xs:string” use=”optional” />
                                    <xs:attribute name=”Description” type=”xs:string” use=”required” />
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute name=”Type” type=”enumScriptType” use=”required”  />
                        <xs:attribute name=”Version” type=”xs:string” use=”optional” />
                        <xs:attribute name=”ConnectionString” type=”xs:string” use=”optional” />
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
            <xs:attribute name=”EmbedAssemblySource” type=”xs:string” use=”optional” />
        </xs:complexType>
    </xs:element>
</xs:schema>

1 <?xml
version=”1.0″
encoding=”utf-8″
?>
2  <!–Created with Liquid XML Studio Developer Edition
9.0.11.3078
(http://www.liquid-technologies.com)–&gt;
3  <xs:schema elementFormDefault=”qualified”
xmlns:xs=”http://www.w3.org/2001/XMLSchema"&gt;
4 <xs:simpleType name=”ruleString”>
5 <xs:restriction base=”xs:string”>
6 <xs:minLength value=”4″
/>
7 <xs:maxLength value=”40″
/>
8 <xs:pattern value=”[a-zA-Z]+”
/>
9 </xs:restriction>
10 </xs:simpleType>
11 <xs:simpleType name=”dbType”>
12 <xs:restriction base=”xs:string”>
13 <xs:enumeration value=”Short”
/>
14 <xs:enumeration value=”Int”
/>
15 <xs:enumeration value=”Long”
/>
16 <xs:enumeration value=”Boolean”
/>
17 <xs:enumeration value=”Decimal”
/>
18 <xs:enumeration value=”DateTime”
/>
19 <xs:enumeration value=”String”
/>
20 </xs:restriction>
21 </xs:simpleType>
22 <xs:complexType name=”commonType”>
23 <xs:sequence minOccurs=”1″
maxOccurs=”1″>
24 <xs:element name=”Name”
type=”ruleString”
minOccurs=”1″
maxOccurs=”1″
/>
25 <xs:element name=”Alias”
type=”ruleString”
minOccurs=”1″
maxOccurs=”1″
/>
26 <xs:element name=”DisplayText”
type=”xs:string”
minOccurs=”1″
maxOccurs=”1″
/>
27 <xs:element name=”Description”
type=”xs:string”
minOccurs=”1″
maxOccurs=”1″
/>
28 </xs:sequence>
29 </xs:complexType>
30 <xs:complexType name=”simpleProperty”>
31 <xs:complexContent>
32 <xs:extension base=”commonType”>
33 <xs:sequence minOccurs=”1″
maxOccurs=”1″>
34 <xs:element name=”DbType”
type=”dbType”
minOccurs=”1″
maxOccurs=”1″
/>
35 <xs:element name=”Size”
type=”xs:int”
minOccurs=”0″
maxOccurs=”1″
/>
36 <xs:element name=”Scale”
type=”xs:int”
minOccurs=”0″
maxOccurs=”1″
/>
37 <xs:element name=”IgnoreInsert”
type=”xs:boolean”
minOccurs=”0″
maxOccurs=”1″
/>
38 <xs:element name=”IgnoreUpdate”
type=”xs:boolean”
minOccurs=”0″
maxOccurs=”1″
/>
39 <xs:element name=”AutoSync”
type=”xs:boolean”
minOccurs=”0″
maxOccurs=”1″
/>
40 <xs:element name=”DefaultValue”
type=”xs:anyType”
minOccurs=”0″
maxOccurs=”1″
/>
41 </xs:sequence>
42 </xs:extension>
43 </xs:complexContent>
44 </xs:complexType>
45 <xs:complexType name=”referenceType”>
46 <xs:complexContent>
47 <xs:extension base=”simpleProperty”>
48 <xs:sequence minOccurs=”1″
maxOccurs=”1″>
49 <xs:element name=”ReferenceDataEntityName”
type=”ruleString”
minOccurs=”1″
maxOccurs=”1″
/>
50 </xs:sequence>
51 </xs:extension>
52 </xs:complexContent>
53 </xs:complexType>
54 <xs:complexType name=”collectionProperty”>
55 <xs:complexContent>
56 <xs:extension base=”commonType”>
57 <xs:sequence minOccurs=”1″
maxOccurs=”1″>
58 <xs:element name=”ItemDataEntityName”
type=”ruleString”
/>
59 </xs:sequence>
60 </xs:extension>
61 </xs:complexContent>
62 </xs:complexType>
63 <xs:complexType name=”properties”>
64 <xs:sequence minOccurs=”0″
maxOccurs=”1″>
65 <xs:element name=”SimpleProperty”
type=”simpleProperty”
minOccurs=”0″
maxOccurs=”unbounded”
/>
66 <xs:element name=”ReferenceProperty”
type=”referenceType”
minOccurs=”0″
maxOccurs=”unbounded”
/>
67 <xs:element name=”Collection”
type=”collectionProperty”
minOccurs=”0″
maxOccurs=”unbounded”
/>
68 </xs:sequence>
69 </xs:complexType>
70 <xs:complexType name=”dataEntity”>
71 <xs:sequence minOccurs=”0″
maxOccurs=”1″>
72 <xs:element name=”Name”
type=”ruleString”
minOccurs=”1″
maxOccurs=”1″
/>
73 <xs:element name=”Alias”
type=”ruleString”
minOccurs=”1″
maxOccurs=”1″
/>
74 <xs:element name=”PrimaryKey”
type=”ruleString”
minOccurs=”1″
maxOccurs=”1″
/>
75 <xs:element name=”Index”
type=”xs:string”
minOccurs=”0″
maxOccurs=”1″
/>
76 <xs:element name=”Properties”
type=”properties”
minOccurs=”1″
maxOccurs=”1″
/>
77 </xs:sequence>
78 </xs:complexType>
79 <xs:complexType name=”dataEntities”>
80 <xs:sequence minOccurs=”0″
maxOccurs=”1″>
81 <xs:element name=”DataEntity”
type=”dataEntity”
minOccurs=”0″
maxOccurs=”unbounded”
/>
82 </xs:sequence>
83 </xs:complexType>
84 <xs:element name=”MetadataContainer”>
85 <xs:complexType>
86 <xs:sequence minOccurs=”0″
maxOccurs=”1″>
87 <xs:element name=”DataEntities”
type=”dataEntities”
/>
88 </xs:sequence>
89 </xs:complexType>
90 </xs:element>
91 </xs:schema>

注意文件中的simpleType
,它表示定义一个自定义的简单类型,在XSD文件的节点中使用 type
属性来引用它即可。

           
除了以上功能之外,它还可以编辑服务相关的wsdl,生成xml相关的各种语言代码,……..

本文中定义了三个自定义类型enumCmdType,enumResultClass,enumScriptType
,而且是枚举类型(使用xs:enumeration 定义),这样在XML文件中就可以出现“下拉选择”的提示效果了。

            当你在veryVcd输入xml
studio就可以下载到该工具,怎么使用呢?你懂的…………

在节点属性中,use=”required”
表示必须的属性,use=”optional”  表示可选的属性。

整个XSD文件的编写要注意的也就这么多,编写起来还是比较简单的。

 

有了这个XSD文件,在建立的Sql-Map配置文件的<sqlmap>
标签中,加入这个XSD的使用声明,就能够看到智能提示的效果了。

 

<SqlMap  

        xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance
        xsi:noNamespaceSchemaLocation=”SqlMap.xsd”>
<!– 在下面敲入尖括号,就能够出现当前节点区域内的应该编写的内容,来试试吧 –>

</SqlMap>

有了这个SqlMap.config文件,就能够使用代码生成器自动生成DAL代码了。

PDF.NET代码生成器下载地址(包含框架应用的完整示例),下载后请看里面的说明。

如果程序的数据库无法打开,请看看连接字符串是否正确,或者将它附加到SQLSERVER实例上:

connectionString=”Data
Source=.\SQLEXPRESS;AttachDbFilename=~\App_Data\PDFTest.mdf;Integrated
Security=True;Connect Timeout=30;User Instance=True”

 

下载完成后,将本文的SqlMap.xsd内容复制下来另存为文件即可,注意文件目录,如果该XSD文件跟SqlMap.config文件不在同一个,需要修改下面的路径:

xsi:noNamespaceSchemaLocation=”SqlMap.xsd”

 

有关PDF.NET框架的详细内容,请看我的博客相关内容或者查看官网:http://www.pwmis.com/sqlmap

 

 

 

相关文章