Esempio n. 1
0
 public BookDB(string filePath = @"\BookDB.sqlite3")
 {
     FilePath = filePath;
     Logger.Debug($"Connect to database: {filePath}");
     DB = new Sqlite3(FilePath);
     CreateTables();
 }
		internal SqliteDataReader (SqliteCommand cmd, Sqlite3.Vdbe pVm, int version)
		{
			command = cmd;
            rows = new List<object[]>();
            column_names_sens = new Dictionary<String, Object>();
            column_names_insens = new Dictionary<String, Object>( StringComparer.InvariantCultureIgnoreCase );
			closed = false;
			current_row = -1;
			reading = true;
			ReadpVm (pVm, version, cmd);
			ReadingDone ();
		}
Esempio n. 3
0
 public static void DbTests()
 {
     var db = new Sqlite3("BookDB.sqlite3");
     using (var r = db.ExecuteReaderOne("select count(*) from book"))
     {
         var v = r.GetValues();
         foreach (var i in Enumerable.Range(0, r.FieldCount))
         {
             Console.WriteLine("{0}: {1}", v.GetKey(i), r.GetValue(i));
         }
     }
 }
Esempio n. 4
0
 private async void _refresh_Click(object sender, RoutedEventArgs e)
 {
     if (_dbFileList.SelectedItem == null)
     {
         return;
     }
     var path = WorkPath.DbPath + @"\" + (string)_dbFileList.SelectedItem;
     var tableName = (string)_dbTableList.SelectedItem;
     _dataViewer.ItemsSource = await Task.Run(() =>
     {
         var db = new Sqlite3(path);
         return db.GetDatas(tableName).DefaultView;
     });
 }
Esempio n. 5
0
        private async void _dbFileList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_dbFileList.SelectedItem == null)
            {
                return;
            }
            var path = WorkPath.DbPath + @"\" + (string)_dbFileList.SelectedItem;
            DbTableList = await Task.Run(() =>
            {
                var db = new Sqlite3(path);
                return new ObservableCollection<string>(db.GetTables());
            });

            OnPropertyChanged(nameof(DbTableList));
        }
Esempio n. 6
0
        internal SqliteDataReader(SqliteCommand cmd, Sqlite3.Vdbe pVm, int version)
        {
            command = cmd;
            rows = new ArrayList();
            column_names_sens = new Hashtable();

            column_names_insens = new Hashtable(CaseInsensitiveHashCodeProvider.DefaultInvariant,
                                 CaseInsensitiveComparer.DefaultInvariant);

            closed = false;
            current_row = -1;
            reading = true;
            ReadpVm(pVm, version, cmd);
            ReadingDone();
        }
Esempio n. 7
0
 public static Result Reset(Sqlite3.Vdbe stmt)
 {
     return((Result)Sqlite3.sqlite3_reset(stmt));
 }
Esempio n. 8
0
 public static int Changes(Sqlite3.sqlite3 db)
 {
     return(Sqlite3.sqlite3_changes(db));
 }
Esempio n. 9
0
 public static Result Close(Sqlite3.sqlite3 db)
 {
     return((Result)Sqlite3.sqlite3_close(db));
 }
Esempio n. 10
0
 public static Result Open(string filename, out Sqlite3.sqlite3 db)
 {
     return((Result)Sqlite3.sqlite3_open(filename, out db));
 }
Esempio n. 11
0
    public bool Step()
    {
        switch (Sqlite3.sqlite3_step(vm))
        {
        case Sqlite3.SQLITE_DONE: return(false);

        case Sqlite3.SQLITE_ROW:
        {
            int columnCount = Sqlite3.sqlite3_column_count(vm);
            columnNames = new string[columnCount];
            columnTypes = new int[columnCount];

            try
            {
                // reads columns one by one
                for (int i = 0; i < columnCount; i++)
                {
                    columnNames[i] = Sqlite3.sqlite3_column_name(vm, i);
                    columnTypes[i] = Sqlite3.sqlite3_column_type(vm, i);
                }
            }
            catch
            {
                throw new Exception("SQLite fail to read column's names and types! error: " + Sqlite3.sqlite3_errmsg(db));
            }

            return(true);
        }
        }
        throw new Exception("SQLite step fail! error: " + Sqlite3.sqlite3_errmsg(db));
    }
Esempio n. 12
0
		// Executes a statement and returns whether there is more data available.
		internal bool ExecuteStatement( Sqlite3.Vdbe pStmt, out int cols, out IntPtr pazValue, out IntPtr pazColName )
		{
			SqliteError err;

			//if (parent_conn.Version == 3) 
			//{
			err = (SqliteError)Sqlite3.sqlite3_step( pStmt );

			if ( err == SqliteError.ERROR )
				throw new SqliteExecutionException(parent_conn.Handle2.errCode, GetError3() + "\n" + pStmt.zErrMsg );

			pazValue = IntPtr.Zero;
			pazColName = IntPtr.Zero; // not used for v=3
			cols = Sqlite3.sqlite3_column_count( pStmt );

			/*
			}
			else 
			{
			err = (SqliteError)Sqlite3.sqlite3_step(pStmt, out cols, out pazValue, out pazColName);
			if (err == SqliteError.ERROR)
			throw new SqliteExecutionException ();
			}
			*/
			if ( err == SqliteError.BUSY )
				throw new SqliteBusyException();

			if ( err == SqliteError.MISUSE )
				throw new SqliteExecutionException();

			// err is either ROW or DONE.
			return err == SqliteError.ROW;
		}
Esempio n. 13
0
 public XMusicDB()
 {
     db = new Sqlite3(FilePath);
     CreateTables();
 }
Esempio n. 14
0
        public double ColumnDouble(IDbStatement stmt, int index)
        {
            var dbStatement = (DbStatement)stmt;

            return(Sqlite3.sqlite3_column_double(dbStatement.InternalStmt, index));
        }
Esempio n. 15
0
        public long ColumnInt64(IDbStatement stmt, int index)
        {
            var dbStatement = (DbStatement)stmt;

            return(Sqlite3.sqlite3_column_int64(dbStatement.InternalStmt, index));
        }
Esempio n. 16
0
        public ColType ColumnType(IDbStatement stmt, int index)
        {
            var dbStatement = (DbStatement)stmt;

            return((ColType)Sqlite3.sqlite3_column_type(dbStatement.InternalStmt, index));
        }
Esempio n. 17
0
		private void GetNextStatement( string pzStart, ref string pzTail, ref Sqlite3.Vdbe pStmt )
		{
			UTF8Encoding encoding = new UTF8Encoding();
			SqliteError err = (SqliteError)Sqlite3.sqlite3_prepare_v2( parent_conn.Handle2, pzStart, pzStart.Length, ref pStmt, ref pzTail );
			if ( err != SqliteError.OK )
				throw new SqliteSyntaxException( parent_conn.Handle2.errCode, GetError3() );
		}
Esempio n. 18
0
 public static long LastInsertRowid(Sqlite3.sqlite3 db)
 {
     return(Sqlite3.sqlite3_last_insert_rowid(db));
 }
Esempio n. 19
0
        public int ColumnBytes(IDbStatement stmt, int index)
        {
            var dbStatement = (DbStatement)stmt;

            return(Sqlite3.sqlite3_column_bytes(dbStatement.InternalStmt, index));
        }
Esempio n. 20
0
 public static int BindParameterIndex(Sqlite3.Vdbe stmt, string name)
 {
     return(Sqlite3.sqlite3_bind_parameter_index(stmt, name));
 }
Esempio n. 21
0
        public byte[] ColumnBlob(IDbStatement stmt, int index)
        {
            var dbStatement = (DbStatement)stmt;

            return(Sqlite3.sqlite3_column_blob(dbStatement.InternalStmt, index));
        }
Esempio n. 22
0
		internal void ReadpVm (Sqlite3.Vdbe pVm, int version, SqliteCommand cmd)
		{
			int pN;
			IntPtr pazValue;
			IntPtr pazColName;
			bool first = true;
			
			int[] declmode = null;

			while (true) {
				bool hasdata = cmd.ExecuteStatement(pVm, out pN, out pazValue, out pazColName);
			
				// For the first row, get the column information
				if (first) {
					first = false;
					
					if (version == 3) {
						// A decltype might be null if the type is unknown to sqlite.
						decltypes = new string[pN];
						declmode = new int[pN]; // 1 == integer, 2 == datetime, 3 == guid
						for (int i = 0; i < pN; i++) {
							string decl = Sqlite3.sqlite3_column_decltype (pVm, i);
							if (decl != null) {
								decltypes[i] = decl.ToLower(System.Globalization.CultureInfo.InvariantCulture);
								if (decltypes[i] == "int" || decltypes[i] == "integer")
									declmode[i] = 1;
								else if (decltypes[i] == "date" || decltypes[i] == "datetime")
									declmode[i] = 2;
                                else if (decltypes[i] == "guid")
                                    declmode[i] = 3;
							}
						}
					}
					
					columns = new string[pN];	
					for (int i = 0; i < pN; i++) {
						string colName;
						//if (version == 2) {
						//	IntPtr fieldPtr = Marshal.ReadIntPtr (pazColName, i*IntPtr.Size);
						//	colName = Sqlite.HeapToString (fieldPtr, ((SqliteConnection)cmd.Connection).Encoding);
						//} else {
							colName = Sqlite3.sqlite3_column_name (pVm, i);
						//}
						columns[i] = colName;
						column_names_sens [colName] = i;
						column_names_insens [colName] = i;
					}
				}

				if (!hasdata) break;
				
				object[] data_row = new object [pN];
				for (int i = 0; i < pN; i++) {
					/*
                    if (version == 2) {
						IntPtr fieldPtr = Marshal.ReadIntPtr (pazValue, i*IntPtr.Size);
						data_row[i] = Sqlite.HeapToString (fieldPtr, ((SqliteConnection)cmd.Connection).Encoding);
					} else {
                    */
						switch (Sqlite3.sqlite3_column_type (pVm, i)) {
							case 1:
								long val = Sqlite3.sqlite3_column_int64 (pVm, i);
							
								// If the column was declared as an 'int' or 'integer', let's play
								// nice and return an int (version 3 only).
								if (declmode[i] == 1 && val >= int.MinValue && val <= int.MaxValue)
									data_row[i] = (int)val;
								
								// Or if it was declared a date or datetime, do the reverse of what we
								// do for DateTime parameters.
								else if (declmode[i] == 2)
									data_row[i] = DateTime.FromFileTime(val);		
								else
									data_row[i] = val;
									
								break;
							case 2:
								data_row[i] = Sqlite3.sqlite3_column_double (pVm, i);
								break;
							case 3:
								data_row[i] = Sqlite3.sqlite3_column_text (pVm, i);
								
								// If the column was declared as a 'date' or 'datetime', let's play
								// nice and return a DateTime (version 3 only).
								if (declmode[i] == 2)
									if (data_row[i] == null) data_row[i] = null;
									else data_row[i] = DateTime.Parse((string)data_row[i], System.Globalization.CultureInfo.InvariantCulture);
                                else if (declmode[i] == 3)
                                    data_row[i] = Guid.Parse((string) data_row[i]);
								break;
							case 4:
								int blobbytes = Sqlite3.sqlite3_column_bytes16 (pVm, i);
								byte[] blob = Sqlite3.sqlite3_column_blob(pVm, i);
								//byte[] blob = new byte[blobbytes];
								//Marshal.Copy (blobptr, blob, 0, blobbytes);
								data_row[i] = blob ?? new byte[0];
								break;
							case 5:
								data_row[i] = null;
								break;
							default:
								throw new Exception ("FATAL: Unknown sqlite3_column_type");
						//}
					}
				}
				
				rows.Add (data_row);
			}
		}
Esempio n. 23
0
        public string GetErrmsg(IDbHandle db)
        {
            var dbHandle = (DbHandle)db;

            return(Sqlite3.sqlite3_errmsg(dbHandle.InternalDbHandle));
        }
Esempio n. 24
0
 private string GetError3()
 {
     return(Sqlite3.sqlite3_errmsg(parent_conn.Handle2));
     //return Marshal.PtrToStringUni (Sqlite.sqlite3_errmsg16 (parent_conn.Handle));
 }
Esempio n. 25
0
        public string ColumnText(IDbStatement stmt, int index)
        {
            var dbStatement = (DbStatement)stmt;

            return(Sqlite3.sqlite3_column_text(dbStatement.InternalStmt, index));
        }
Esempio n. 26
0
        private void BindParameter(CodeContext context, int index, object arg)
        {
            int rc;

            if (arg == null)
            {
                rc = Sqlite3.sqlite3_bind_null(st, index);
            }
            else if (arg is int)
            {
                rc = Sqlite3.sqlite3_bind_int(st, index, (int)arg);
            }
            else if (arg is bool)
            {
                rc = Sqlite3.sqlite3_bind_int(st, index, (bool)arg ? 1 : 0);
            }
            else if (arg is long)
            {
                rc = Sqlite3.sqlite3_bind_int64(st, index, (long)arg);
            }
            else if (arg is Microsoft.Scripting.Math.BigInteger)
            {
                rc = Sqlite3.sqlite3_bind_int64(st, index, ((Microsoft.Scripting.Math.BigInteger)arg).ToInt64());
            }
            else if (arg is System.Numerics.BigInteger)
            {
                rc = Sqlite3.sqlite3_bind_int64(st, index, (long)((System.Numerics.BigInteger)arg));
            }
            else if (arg is float)
            {
                rc = Sqlite3.sqlite3_bind_double(st, index, (float)arg);
            }
            else if (arg is double)
            {
                rc = Sqlite3.sqlite3_bind_double(st, index, (double)arg);
            }
            else if (arg is string)
            {
                rc = Sqlite3.sqlite3_bind_text(st, index, (string)arg, -1, Sqlite3.SQLITE_TRANSIENT);
            }
            else if (arg is byte[])
            {
                rc = Sqlite3.sqlite3_bind_blob(this.st, index, (byte[])arg, -1, Sqlite3.SQLITE_TRANSIENT);
            }
            else if (arg is PythonBuffer)
            {
                //TODO: see if there is a better way to do this
                PythonBuffer buffer = (PythonBuffer)arg;
                string       s      = buffer[new Slice(0, null)].ToString();
                byte[]       bytes  = PythonSQLite.Latin1.GetBytes(s);

                rc = Sqlite3.sqlite3_bind_blob(this.st, index, bytes, -1, Sqlite3.SQLITE_TRANSIENT);
            }
            else
            {
                throw PythonSQLite.MakeInterfaceError("Unable to bind parameter {0} - unsupported type {1}".Format(index, arg.GetType()));
            }

            if (rc != Sqlite3.SQLITE_OK)
            {
                throw PythonSQLite.MakeInterfaceError("Unable to bind parameter {0}: {1}".Format(index, Sqlite3.sqlite3_errmsg(db)));
            }
        }
Esempio n. 27
0
        public Result EnableLoadExtension(IDbHandle db, int onoff)
        {
            var dbHandle = (DbHandle)db;

            return((Result)Sqlite3.sqlite3_enable_load_extension(dbHandle.InternalDbHandle, onoff));
        }
Esempio n. 28
0
 public static Result Open(string filename, out Sqlite3.sqlite3 db, int flags, IntPtr zVfs)
 {
     return((Result)Sqlite3.sqlite3_open_v2(filename, out db, flags, null));
 }
Esempio n. 29
0
        public Result Close(IDbHandle db)
        {
            var dbHandle = (DbHandle)db;

            return((Result)Sqlite3.sqlite3_close(dbHandle.InternalDbHandle));
        }
Esempio n. 30
0
 public static Result BusyTimeout(Sqlite3.sqlite3 db, int milliseconds)
 {
     return((Result)Sqlite3.sqlite3_busy_timeout(db, milliseconds));
 }
Esempio n. 31
0
        public Result BusyTimeout(IDbHandle db, int milliseconds)
        {
            var dbHandle = (DbHandle)db;

            return((Result)Sqlite3.sqlite3_busy_timeout(dbHandle.InternalDbHandle, milliseconds));
        }
Esempio n. 32
0
 public static Result Step(Sqlite3.Vdbe stmt)
 {
     return((Result)Sqlite3.sqlite3_step(stmt));
 }
Esempio n. 33
0
        public int Changes(IDbHandle db)
        {
            var dbHandle = (DbHandle)db;

            return(Sqlite3.sqlite3_changes(dbHandle.InternalDbHandle));
        }
Esempio n. 34
0
 public static Result Finalize(Sqlite3.Vdbe stmt)
 {
     return((Result)Sqlite3.sqlite3_finalize(stmt));
 }
Esempio n. 35
0
        public Result Reset(IDbStatement stmt)
        {
            var dbStatement = (DbStatement)stmt;

            return((Result)Sqlite3.sqlite3_reset(dbStatement.InternalStmt));
        }
Esempio n. 36
0
 public static string GetErrmsg(Sqlite3.sqlite3 db)
 {
     return(Sqlite3.sqlite3_errmsg(db));
 }
Esempio n. 37
0
		private void BindParameters3( Sqlite3.Vdbe pStmt )
		{
			if ( sql_params == null )
				return;
			if ( sql_params.Count == 0 )
				return;

			int pcount = Sqlite3.sqlite3_bind_parameter_count( pStmt );

			for ( int i = 1; i <= pcount; i++ )
			{
				String name = Sqlite3.sqlite3_bind_parameter_name( pStmt, i );

				SqliteParameter param = null;
        if ( !String.IsNullOrEmpty( name ) )
          param = sql_params[name] as SqliteParameter;
				else
					param = sql_params[i - 1] as SqliteParameter;

				if ( param.Value == null )
				{
					Sqlite3.sqlite3_bind_null( pStmt, i );
					continue;
				}

				Type ptype = param.Value.GetType();
				if ( ptype.IsEnum )
					ptype = Enum.GetUnderlyingType( ptype );

				SqliteError err;

				if ( ptype.Equals( typeof( String ) ) )
				{
					String s = (String)param.Value;
					err = (SqliteError)Sqlite3.sqlite3_bind_text( pStmt, i, s, -1, null );
				} else if ( ptype.Equals( typeof( DBNull ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_null( pStmt, i );
				} else if ( ptype.Equals( typeof( Boolean ) ) )
				{
					bool b = (bool)param.Value;
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, b ? 1 : 0 );
				} else if ( ptype.Equals( typeof( Byte ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, (Byte)param.Value );
				} else if ( ptype.Equals( typeof( Char ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, (Char)param.Value );
				} else if ( ptype.IsEnum )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, (Int32)param.Value );
				} else if ( ptype.Equals( typeof( Int16 ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, (Int16)param.Value );
				} else if ( ptype.Equals( typeof( Int32 ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, (Int32)param.Value );
				} else if ( ptype.Equals( typeof( SByte ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, (SByte)param.Value );
				} else if ( ptype.Equals( typeof( UInt16 ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, (UInt16)param.Value );
				} else if ( ptype.Equals( typeof( DateTime ) ) )
				{
					DateTime dt = (DateTime)param.Value;
					err = (SqliteError)Sqlite3.sqlite3_bind_text( pStmt, i, dt.ToString( "yyyy-MM-dd HH:mm:ss.fff"), -1, null );
				} else if ( ptype.Equals( typeof( Decimal ) ) )
				{
					string val = ( (Decimal)param.Value ).ToString( CultureInfo.InvariantCulture );
					err = (SqliteError)Sqlite3.sqlite3_bind_text( pStmt, i, val, val.Length, null );
				} else if ( ptype.Equals( typeof( Double ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_double( pStmt, i, (Double)param.Value );
				} else if ( ptype.Equals( typeof( Single ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_double( pStmt, i, (Single)param.Value );
				} else if ( ptype.Equals( typeof( UInt32 ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int64( pStmt, i, (UInt32)param.Value );
				} else if ( ptype.Equals( typeof( Int64 ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int64( pStmt, i, (Int64)param.Value );
				} else if ( ptype.Equals( typeof( Byte[] ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_blob( pStmt, i, (byte[])param.Value, ( (byte[])param.Value ).Length, null );
				} else if ( ptype.Equals( typeof( Guid ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_text( pStmt, i, param.Value.ToString(), param.Value.ToString().Length, null );
				} else
				{
					throw new ApplicationException( "Unkown Parameter Type" );
				}
				if ( err != SqliteError.OK )
				{
					throw new ApplicationException( "Sqlite error in bind " + err );
				}
			}
		}
Esempio n. 38
0
 public static int BindNull(Sqlite3.Vdbe stmt, int index)
 {
     return(Sqlite3.sqlite3_bind_null(stmt, index));
 }
Esempio n. 39
0
        public SqliteDataReader ExecuteReader(CommandBehavior behavior, bool want_results, out int rows_affected)
        {
            Prepare();

            // The SQL string may contain multiple sql commands, so the main
            // thing to do is have Sqlite iterate through the commands.
            // If want_results, only the last command is returned as a
            // DataReader.	Otherwise, no command is returned as a
            // DataReader.

            //IntPtr psql; // pointer to SQL command

            // Sqlite 2 docs say this: By default, SQLite assumes that all data uses a fixed-size 8-bit
            // character (iso8859).	But if you give the --enable-utf8 option to the configure script, then the
            // library assumes UTF-8 variable sized characters. This makes a difference for the LIKE and GLOB
            // operators and the LENGTH() and SUBSTR() functions. The static string sqlite_encoding will be set
            // to either "UTF-8" or "iso8859" to indicate how the library was compiled. In addition, the sqlite.h
            // header file will define one of the macros SQLITE_UTF8 or SQLITE_ISO8859, as appropriate.
            //
            // We have no way of knowing whether Sqlite 2 expects ISO8859 or UTF-8, but ISO8859 seems to be the
            // default.	Therefore, we need to use an ISO8859(-1) compatible encoding, like ANSI.
            // OTOH, the user may want to specify the encoding of the bytes stored in the database, regardless
            // of what Sqlite is treating them as,

            // For Sqlite 3, we use the UTF-16 prepare function, so we need a UTF-16 string.

            /*
             * if (parent_conn.Version == 2)
             * psql = Sqlite.StringToHeap (sql.Trim(), parent_conn.Encoding);
             * else
             * psql = Marshal.StringToHGlobalUni (sql.Trim());
             */
            string queryval = sql.Trim();
            string pzTail   = sql.Trim();
            IntPtr errMsgPtr;

            parent_conn.StartExec();

            rows_affected = 0;

            try
            {
                while (true)
                {
                    Sqlite3.Vdbe pStmt = null;

                    queryval = pzTail;
                    GetNextStatement(queryval, ref pzTail, ref pStmt);

                    if (pStmt == null)
                    {
                        throw new Exception();
                    }

                    // pzTail is positioned after the last byte in the
                    // statement, which will be the NULL character if
                    // this was the last statement.
                    bool last = pzTail.Length == 0;

                    try
                    {
                        if (parent_conn.Version == 3)
                        {
                            BindParameters3(pStmt);
                        }

                        if (last && want_results)
                        {
                            return(new SqliteDataReader(this, pStmt, parent_conn.Version));
                        }

                        ExecuteStatement(pStmt);

                        if (last)                           // rows_affected is only used if !want_results
                        {
                            rows_affected = NumChanges();
                        }
                    }
                    finally
                    {
                        //if (parent_conn.Version == 3)
                        Sqlite3.sqlite3_finalize(pStmt);
                        //else
                        //	Sqlite.sqlite_finalize (pStmt, out errMsgPtr);
                    }

                    if (last)
                    {
                        break;
                    }
                }

                return(null);
            }
            //alxwest: Console.WriteLine in shared functionality.
            //catch ( Exception ex )
            //{
            //    Console.WriteLine( ex.Message );
            //    return null;
            //}
            finally
            {
                parent_conn.EndExec();
                //Marshal.FreeHGlobal (psql);
            }
        }
Esempio n. 40
0
 public XMusicDB(string path)
 {
     FilePath = path;
     db = new Sqlite3(path);
     CreateTables();
 }
Esempio n. 41
0
 public string GetLastError()
 {
     return(Sqlite3.sqlite3_errmsg(parent_conn.Handle2));
 }
Esempio n. 42
0
        private void BindParameters3(Sqlite3.Vdbe pStmt)
        {
            if (sql_params == null)
            {
                return;
            }
            if (sql_params.Count == 0)
            {
                return;
            }

            int pcount = Sqlite3.sqlite3_bind_parameter_count(pStmt);

            for (int i = 1; i <= pcount; i++)
            {
                String name = Sqlite3.sqlite3_bind_parameter_name(pStmt, i);

                SqliteParameter param = null;
                if (!String.IsNullOrEmpty(name))
                {
                    param = sql_params[name] as SqliteParameter;
                }
                else
                {
                    param = sql_params[i - 1] as SqliteParameter;
                }

                if (param.Value == null)
                {
                    Sqlite3.sqlite3_bind_null(pStmt, i);
                    continue;
                }

                Type ptype = param.Value.GetType();
                if (ptype.IsEnum)
                {
                    ptype = Enum.GetUnderlyingType(ptype);
                }

                SqliteError err;

                if (ptype.Equals(typeof(String)))
                {
                    String s = (String)param.Value;
                    err = (SqliteError)Sqlite3.sqlite3_bind_text(pStmt, i, s, -1, null);
                }
                else if (ptype.Equals(typeof(DBNull)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_null(pStmt, i);
                }
                else if (ptype.Equals(typeof(Boolean)))
                {
                    bool b = (bool)param.Value;
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, b ? 1 : 0);
                }
                else if (ptype.Equals(typeof(Byte)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, (Byte)param.Value);
                }
                else if (ptype.Equals(typeof(Char)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, (Char)param.Value);
                }
                else if (ptype.IsEnum)
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, (Int32)param.Value);
                }
                else if (ptype.Equals(typeof(Int16)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, (Int16)param.Value);
                }
                else if (ptype.Equals(typeof(Int32)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, (Int32)param.Value);
                }
                else if (ptype.Equals(typeof(SByte)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, (SByte)param.Value);
                }
                else if (ptype.Equals(typeof(UInt16)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int(pStmt, i, (UInt16)param.Value);
                }
                else if (ptype.Equals(typeof(DateTime)))
                {
                    DateTime dt = (DateTime)param.Value;
                    err = (SqliteError)Sqlite3.sqlite3_bind_text(pStmt, i, dt.ToString("yyyy-MM-dd HH:mm:ss.fff"), -1, null);
                }
                else if (ptype.Equals(typeof(Decimal)))
                {
                    string val = ((Decimal)param.Value).ToString(CultureInfo.InvariantCulture);
                    err = (SqliteError)Sqlite3.sqlite3_bind_text(pStmt, i, val, val.Length, null);
                }
                else if (ptype.Equals(typeof(Double)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_double(pStmt, i, (Double)param.Value);
                }
                else if (ptype.Equals(typeof(Single)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_double(pStmt, i, (Single)param.Value);
                }
                else if (ptype.Equals(typeof(UInt32)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int64(pStmt, i, (UInt32)param.Value);
                }
                else if (ptype.Equals(typeof(Int64)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_int64(pStmt, i, (Int64)param.Value);
                }
                else if (ptype.Equals(typeof(Byte[])))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_blob(pStmt, i, (byte[])param.Value, ((byte[])param.Value).Length, null);
                }
                else if (ptype.Equals(typeof(Guid)))
                {
                    err = (SqliteError)Sqlite3.sqlite3_bind_text(pStmt, i, param.Value.ToString(), param.Value.ToString().Length, null);
                }
                else
                {
                    throw new ApplicationException("Unkown Parameter Type");
                }
                if (err != SqliteError.OK)
                {
                    throw new ApplicationException("Sqlite error in bind " + err);
                }
            }
        }
Esempio n. 43
0
		// Executes a statement and ignores its result.
		private void ExecuteStatement( Sqlite3.Vdbe pStmt )
		{
			int cols;
			IntPtr pazValue, pazColName;
			ExecuteStatement( pStmt, out cols, out pazValue, out pazColName );
		}