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 int getExtendedErrcode()
00093 {
00094 return osqlite3_getExtendedErrcode( m_impl );
00095 }
00096
00101 public string getLastErrMsg()
00102 {
00103 return StringFromC.String( osqlite3_getLastErrMsg( m_impl ) );
00104 }
00105
00110 public OSQLiteStmtWrap CreateStmt()
00111 {
00112 return new OSQLiteStmtWrap( this );
00113 }
00114
00118 public void Interrupt()
00119 {
00120 osqlite3_interrupt( m_impl );
00121 }
00122
00127 public int getChanges()
00128 {
00129 return osqlite3_changes( m_impl );
00130 }
00131
00136 public long getLastInsertROWID()
00137 {
00138 long lVal = 0;
00139 osqlite3_last_insert_rowid( m_impl, ref lVal );
00140 return lVal;
00141 }
00142
00143 #region アンマネージ定義
00144 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00145 protected extern static IntPtr osqlite3_new();
00146
00147 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00148 protected extern static void osqlite3_delete( IntPtr instance );
00149
00150 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00151 protected extern static bool osqlite3_open( IntPtr instance, string filename );
00152
00153 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00154 protected extern static void osqlite3_close( IntPtr instance );
00155
00156 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00157 protected extern static IntPtr osqlite3_libversion( IntPtr instance );
00158
00159 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00160 protected extern static int osqlite3_getLastErr( IntPtr instance );
00161
00162 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00163 protected extern static int osqlite3_getExtendedErrcode( IntPtr instance );
00164
00165 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00166 protected extern static IntPtr osqlite3_getLastErrMsg( IntPtr instance );
00167
00168 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00169 protected extern static void osqlite3_interrupt( IntPtr instance );
00170
00171 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00172 protected extern static int osqlite3_changes( IntPtr instance );
00173
00174 [DllImport("osqlite.dll",CharSet = CharSet.Unicode)]
00175 protected extern static void osqlite3_last_insert_rowid( IntPtr instance, ref long val );
00176
00177 #endregion
00178
00179 }
00180 }