//
//
//  Copryright 2011 @ S1N1.COM.All rights reseved.
//
//  Project : OPS.Data
//  File Name : SQLiteFactory.cs
//  Date : 8/19/2011
//  Author : ÁõÃú
//
//

using System.Data.Common;
using Mono.Data.Sqlite;
using System.Collections.Generic;

namespace JR.DevFw.Data
{
    public class MonoSQLiteFactory : IDbDialect
    {
        private string connectionString;

        public MonoSQLiteFactory(string connectionString)
        {
            this.connectionString = connectionString;
        }

        public  DbConnection GetConnection()
        {
            return new SqliteConnection(this.connectionString);
        }

        public  DbParameter CreateParameter(string name, object value)
        {
            return new SqliteParameter(name, value);
        }

        public  DbCommand CreateCommand(string sql)
        {
            return new SqliteCommand(sql);
        }

        public  DbDataAdapter CreateDataAdapter(DbConnection connection, string sql)
        {
            return new SqliteDataAdapter(sql, (SqliteConnection) connection);
        }

        public int ExecuteScript(DbConnection conn, RowAffer r, string sql, string delimiter)
        {
            int result = 0;
            string[] array = sql.Split(';');
            foreach (string s in array)
            {
                result += r(s);
            }
            return result;
        }

        public string GetConnectionString()
        {
            return this.connectionString;
        }

        public DbParameter[] ParseParameters(IDictionary<string, object> paramMap)
        {
            return DataUtil.ParameterMapToArray(this, paramMap);
        }
    }
}