Exemple #1
0
        /// <summary>
        /// Gets a list with all PCA coordinates stored in the database.
        /// </summary>
        /// <returns>
        /// A <see cref="List<DataEntry>"/> containing all PCA coordinates
        /// from the database.
        /// </returns>
        public List<DataEntry> GetPcaCoordinates ()
        {
            List<DataEntry> ret = new List<DataEntry> ();

            IDbCommand dbcmd = null;
            try {
                dbcon.Open ();
                dbcmd = dbcon.CreateCommand ();

                dbcmd.CommandText = "SELECT pca_x, pca_y, banshee_id FROM PCAData";
                System.Data.IDataReader reader = dbcmd.ExecuteReader ();
                while (reader.Read ()) {
                    int bid = reader.GetInt32 (2);
                    DataEntry de = new DataEntry (bid, reader.GetDouble (0), reader.GetDouble (1));
                    ret.Add (de);
                }

                return ret;
            } catch (Exception e) {
                Log.Exception ("NoNoise/DB - PCA data read failed", e);
                return null;
            } finally {
                if (dbcmd != null)
                    dbcmd.Dispose ();
                dbcmd = null;
                if (dbcon != null)
                    dbcon.Close ();
            }
        }
Exemple #2
0
        /// <summary>
        /// Inserts one DataEntry into the PCAData table.
        /// </summary>
        /// <param name="de">
        /// The <see cref="DataEntry"/> to be inserted
        /// </param>
        /// <returns>
        /// True if the DataEntry was successfully inserted. False otherwise.
        /// </returns>
        public bool InsertPcaCoordinate(DataEntry de)
        {
            IDbCommand dbcmd = null;
            try {
                dbcon.Open();
                dbcmd = dbcon.CreateCommand();

                dbcmd.CommandText = string.Format(
                        "INSERT INTO PCAData (banshee_id, pca_x, pca_y) VALUES ('{0}', '{1}', '{2}')",
                        de.ID, de.X, de.Y);
                dbcmd.ExecuteNonQuery ();
            } catch (Exception e) {
                Log.Exception("NoNoise/DB - DataEntry insert failed for DE: " + de, e);
                return false;
            } finally {
                if (dbcmd != null)
                    dbcmd.Dispose();
                dbcmd = null;
                if (dbcon != null)
                    dbcon.Close();
            }

            return true;
        }
Exemple #3
0
        /// <summary>
        /// Inserts one DataEntry into the PCAData table.
        /// The database connection has to be opened before calling this method
        /// and should be closed afterwards.
        /// </summary>
        /// <param name="de">
        /// The <see cref="DataEntry"/> to be inserted
        /// </param>
        /// <returns>
        /// True if the DataEntry was successfully inserted. False otherwise.
        /// </returns>
        private bool InsertPcaCoordinate (DataEntry de)
        {
            IDbCommand dbcmd = null;
            try {
                dbcmd = dbcon.CreateCommand ();

                dbcmd.CommandText = "INSERT INTO PCAData (banshee_id, pca_x, pca_y) VALUES (@bid, @x, @y)";

                SqliteParameter id = new SqliteParameter ("@bid", de.ID);
                SqliteParameter x = new SqliteParameter ("@x", de.X);
                SqliteParameter y = new SqliteParameter ("@y", de.Y);
                x.DbType = DbType.Double;
                y.DbType = DbType.Double;
                dbcmd.Parameters.Add (id);
                dbcmd.Parameters.Add (x);
                dbcmd.Parameters.Add (y);
                dbcmd.Prepare ();

                dbcmd.ExecuteNonQuery ();
            } catch (Exception e) {
                Log.Exception (string.Format ("NoNoise/DB - DataEntry insert failed for DE: {0}", de), e);
                return false;
            } finally {
                if (dbcmd != null)
                    dbcmd.Dispose ();
                dbcmd = null;
            }

            return true;
        }