00001 using System;
00002 using System.ComponentModel;
00003 using System.Collections;
00004 using System.Data;
00005
00006 using SQLiteCSLib.Inner;
00007
00008 namespace SQLiteCSLib
00009 {
00013 public class SQLiteConnection : Component, IDbConnection, IDisposable
00014 {
00018 protected OSQLiteDBWrap m_db = null;
00019
00024 protected string m_connectstring = "";
00025
00029 internal OSQLiteDBWrap OSQLiteDB
00030 {
00031 get
00032 {
00033 return m_db;
00034 }
00035 }
00036
00040 public SQLiteConnection()
00041 {
00042 m_db = new OSQLiteDBWrap();
00043 }
00044
00049 public SQLiteConnection( string connectstring )
00050 {
00051 ConnectionString = connectstring;
00052 m_db = new OSQLiteDBWrap();
00053 }
00054
00060 public void ChangeDatabase(string databaseName)
00061 {
00062 }
00063
00070 public IDbTransaction BeginTransaction(IsolationLevel il)
00071 {
00072 return BeginTransaction();
00073 }
00074
00079 public IDbTransaction BeginTransaction()
00080 {
00081 return new SQLiteTransaction( this );
00082 }
00083
00087 public ConnectionState State
00088 {
00089 get
00090 {
00091 if( m_db == null )
00092 return ConnectionState.Closed;
00093
00094 return ConnectionState.Open;
00095 }
00096 }
00097
00101 public string ConnectionString
00102 {
00103 get
00104 {
00105 return m_connectstring;
00106 }
00107 set
00108 {
00109 m_connectstring = value;
00110 }
00111 }
00112
00117 public IDbCommand CreateCommand()
00118 {
00119 return new SQLiteCommand( this );
00120 }
00121
00125 public void Open()
00126 {
00127 Close();
00128
00129 m_db = new OSQLiteDBWrap();
00130 if( m_db.Open( m_connectstring ) == false )
00131 {
00132 m_db = null;
00133
00134 throw new DataException( m_db.getLastErrMsg(), null );
00135 }
00136 }
00137
00141 public void Close()
00142 {
00143 if( m_db != null )
00144 {
00145 m_db.Close();
00146 m_db = null;
00147 }
00148 }
00149
00154 public string Database
00155 {
00156 get
00157 {
00158 return string.Format("SQLite3 {0}", m_db.getLibVersion() );
00159 }
00160 }
00161
00166 public int ConnectionTimeout
00167 {
00168 get
00169 {
00170 return 0;
00171 }
00172 }
00173
00177 new public void Dispose()
00178 {
00179 Close();
00180
00181 foreach( OSQLiteFunc userfunc in m_userfunclist )
00182 {
00183 userfunc.Dispose();
00184 }
00185
00186 foreach( OSQLiteCollation usercoll in m_usercollationlist )
00187 {
00188 usercoll.Dispose();
00189 }
00190 }
00191
00196 public long getLastInsertROWID()
00197 {
00198 return m_db.getLastInsertROWID();
00199 }
00200
00201 #region ユーザ定義関数
00202
00206 protected ArrayList m_userfunclist = new ArrayList();
00207
00215 public ResultEnum CreateFunction( string funcname, int inArg, ICallUserFunction iCallinterface )
00216 {
00217 OSQLiteFunc userfunc = new OSQLiteFunc( m_db, iCallinterface );
00218 m_userfunclist.Add( userfunc );
00219 return userfunc.CreateFunction( funcname, inArg );
00220 }
00221
00222 #endregion
00223
00224 #region ユーザ定義照合順序関数
00225
00229 protected ArrayList m_usercollationlist = new ArrayList();
00230
00237 public ResultEnum CreateCollation( string funcname, ICollationFunction iCallinterface )
00238 {
00239 OSQLiteCollation usercollation = new OSQLiteCollation( m_db, iCallinterface );
00240 m_usercollationlist.Add( usercollation );
00241 return usercollation.CreateFunction( funcname );
00242 }
00243
00244 #endregion
00245
00246 }
00247 }