00001 using System;
00002 using System.IO;
00003 using System.Runtime.InteropServices;
00004
00005 namespace SQLiteCSLib.Inner
00006 {
00010 public class OSQLiteDBWrap : IDisposable
00011 {
00015 protected IntPtr m_impl = IntPtr.Zero;
00016
00021 internal IntPtr internaldb() { return m_impl; }
00022
00026 public OSQLiteDBWrap()
00027 {
00028 m_impl = osqlite3_new();
00029 }
00030
00034 ‾OSQLiteDBWrap()
00035 {
00036 Dispose();
00037 }
00038
00042 public void Dispose()
00043 {
00044 if( m_impl != IntPtr.Zero )
00045 {
00046 osqlite3_delete( m_impl );
00047 m_impl = IntPtr.Zero;
00048 }
00049
00050 }
00051
00057 public bool Open( string filename )
00058 {
00059 return osqlite3_open( m_impl, filename );
00060 }
00061
00065 public void Close()
00066 {
00067 osqlite3_close( m_impl );
00068 }
00069
00074 public string getLibVersion()
00075 {
00076 return StringFromC.StringAnsi( osqlite3_libversion( m_impl ) );
00077 }
00078
00083 public ResultEnum getLastErr()
00084 {
00085 return (ResultEnum)osqlite3_getLastErr( m_impl );
00086 }
00087
00092 public string getLastErrMsg()
00093 {
00094 return StringFromC.String( osqlite3_getLastErrMsg( m_impl ) );
00095 }
00096
00101 public OSQLiteStmtWrap CreateStmt()
00102 {
00103 return new OSQLiteStmtWrap( this );
00104 }
00105
00109 public void Interrupt()
00110 {
00111 osqlite3_interrupt( m_impl );
00112 }
00113
00118 public int getChanges()
00119 {
00120 return osqlite3_changes( m_impl );
00121 }
00122
00127 public long getLastInsertROWID()
00128 {
00129 long lVal = 0;
00130 osqlite3_last_insert_rowid( m_impl, ref lVal );
00131 return lVal;
00132 }
00133
00134 #region アンマネージ定義
00135 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00136 protected extern static IntPtr osqlite3_new();
00137
00138 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00139 protected extern static void osqlite3_delete( IntPtr instance );
00140
00141 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00142 protected extern static bool osqlite3_open( IntPtr instance, string filename );
00143
00144 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00145 protected extern static void osqlite3_close( IntPtr instance );
00146
00147 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00148 protected extern static IntPtr osqlite3_libversion( IntPtr instance );
00149
00150 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00151 protected extern static int osqlite3_getLastErr( IntPtr instance );
00152
00153 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00154 protected extern static IntPtr osqlite3_getLastErrMsg( IntPtr instance );
00155
00156 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00157 protected extern static void osqlite3_interrupt( IntPtr instance );
00158
00159 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00160 protected extern static int osqlite3_changes( IntPtr instance );
00161
00162 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00163 protected extern static void osqlite3_last_insert_rowid( IntPtr instance, ref long val );
00164
00165 #endregion
00166
00167 }
00168 }