IBatis配置SQLite

1、在项目中添加System.Data.SQLite.dll文件

2、在Providers.config中配置Provider:

 <provider name="SQLite3"
     description="SQLite, SQLite.NET providerV1.0.66.0"
     enabled="true"
     assemblyName="System.Data.SQLite,Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139"
    connectionClass="System.Data.SQLite.SQLiteConnection"
    commandClass="System.Data.SQLite.SQLiteCommand"
    parameterClass="System.Data.SQLite.SQLiteParameter"
     parameterDbTypeClass="System.Data.SQLite.SQLiteType"
     parameterDbTypeProperty="DbType"
    dataAdapterClass="System.Data.SQLite.SQLiteDataAdapter"
    commandBuilderClass="System.Data.SQLite.SQLiteCommandBuilder"
     usePositionalParameters="false"
     useParameterPrefixInSql="true"
     useParameterPrefixInParameter="true"
     parameterPrefix="@"
     setDbParameterPrecision="false"
     setDbParameterScale="false"
     allowMARS="false"
  />

其中1.0.66.0为添加进去的System.Data.SQLite.dll的版本,可通过其属性进行查看。enable属性设置为“true”,表示SQLite3的数据库驱动可以使用。

3.在app.config中设置要使用的数据库的连接字符串,然后把数据库文件添加到项目中即可:
    <!--连接字符串-->
    <add key="Host" value=""/>
    <add key="UserName" value="root"/>
    <add key="Password" value=""/>
    <add key="Database"value="ewei_chainsclient.db"/>
    <add key="Port" value="3306"/>
    <add key="DbTemplate" value="DataSource={3}; Version=3;"/>

同时在<configuration>节点内配置<startup>节点,使SQLite能在Framwork4.0中可以使用:

<startupuseLegacyV2RuntimeActivationPolicy="true">

    <supportedRuntimeversion="v4.0"/>

  </startup>

 

4、创建sqlMap.config,与MySql的sqlMap.config文件相同,但需要把原来文件中去除外键的语句去掉(SET FOREIGN_KEY_CHECKS = 0;去掉):

<?xml version="1.0" encoding="utf-8"?>
<sqlMap namespace="ewei.DAL.ShopManagement.Shop"xmlns="http://ibatis.apache.org/mapping"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <!-- 数据库映射关系-->
  <alias>
    <typeAlias alias="Shops"type="ewei.IDAL.ShopManagement.model.Shop,ewei.IDAL.ShopManagement"/>
  </alias>
  <!-- 结果对象的封装 -->
  <resultMaps>
    <!-- 主实体映射 -->
    <resultMap id="ShopResult"class="Shops">
      <result property="ShopCode"column="shopCode"/>
    </resultMap>
  </resultMaps>
  <cacheModels>
    <cacheModel id="Shops-Cache"implementation="LRU" serialize="false">
      <flushInterval hours="24"/>
      <flushOnExecutestatement="Shops.insert"/>
      <flushOnExecute statement="Shops.update"/>
      <flushOnExecutestatement="Shops.delete"/>
      <property name="CacheSize"value="20"/>
    </cacheModel>
  </cacheModels>

 <statements>
    <sql id ="shopShop.listSql">
      SELECT
      shopCode      <!-- 店铺编码 -->
      FROM SE_Shop
    </sql>
    
    <!-- 查询单个店铺,参数类型固定为[map],结果类型为店铺,查询使用缓冲 -->
    <select id="shopShop.object"parameterClass="map" resultMap="ShopResult"cacheModel="Shop-Cache">
      <includerefid="shopShop.listSql"/>
      <dynamic prepend=" WHERE ">
        <isNotNullproperty="shop.ShopCode" prepend="AND">
          shopCode =#shop.ShopCode#
        </isNotNull>
      </dynamic>
    </select>

</statements>
</sqlMap>

即可。

 

到目前为止,查询功能已经实现,但是在做增删改的操作时,操作未提交到SQLite数据文件中去,比如插入的数据不能在数据库中查询到。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值