Exemple #1
0
        /// <summary>
        /// Add a track to the database using the given track-id
        /// </summary>
        /// <param name="trackid">track-id to use</param>
        /// <param name="audioFeature">the audiofeature object</param>
        /// <returns>-1 if failed otherwise the track-id passed</returns>
        public int AddTrack(ref int trackid, AudioFeature audioFeature)
        {
            IDbDataParameter dbTrackIdParam = new SQLiteParameter("@trackid", DbType.Int64);
            IDbDataParameter dbAudioFeatureParam = new SQLiteParameter("@audioFeature", DbType.Binary);
            IDbDataParameter dbNameParam = new SQLiteParameter("@name", DbType.String);
            IDbDataParameter dbDurationParam = new SQLiteParameter("@duration", DbType.Int64);
            IDbDataParameter dbBitStringParam = new SQLiteParameter("@bitstring", DbType.String);

            dbTrackIdParam.Value = trackid;
            dbAudioFeatureParam.Value = audioFeature.ToBytes();
            dbNameParam.Value = audioFeature.Name;
            dbDurationParam.Value = audioFeature.Duration;
            dbBitStringParam.Value = audioFeature.BitString;

            IDbCommand dbcmd;
            lock (dbcon) {
                dbcmd = dbcon.CreateCommand();
            }
            dbcmd.CommandText = "INSERT INTO mirage (trackid, audioFeature, name, duration, bitstring) " +
                "VALUES (@trackid, @audioFeature, @name, @duration, @bitstring)";
            dbcmd.Parameters.Add(dbTrackIdParam);
            dbcmd.Parameters.Add(dbAudioFeatureParam);
            dbcmd.Parameters.Add(dbNameParam);
            dbcmd.Parameters.Add(dbDurationParam);
            dbcmd.Parameters.Add(dbBitStringParam);

            try {
                dbcmd.ExecuteNonQuery();
            } catch (SQLiteException) {
                return -1;
            }

            //trackid++;
            return trackid;
        }
Exemple #2
0
        /// <summary>
        /// Add a track N number of times to the database starting with the given track-id
        /// </summary>
        /// <param name="trackid">track-id to start with</param>
        /// <param name="audioFeature">the audiofeature object</param>
        /// <returns>the track-ids inserted</returns>
        public int[] AddTracks(ref int trackid, AudioFeature audioFeature)
        {
            IDbDataParameter dbTrackIdParam = new SQLiteParameter("@trackid", DbType.Int64);
            IDbDataParameter dbAudioFeatureParam = new SQLiteParameter("@audioFeature", DbType.Binary);
            IDbDataParameter dbNameParam = new SQLiteParameter("@name", DbType.String);
            IDbDataParameter dbDurationParam = new SQLiteParameter("@duration", DbType.Int64);
            IDbDataParameter dbBitStringParam = new SQLiteParameter("@bitstring", DbType.String);
            IDbDataParameter dbSignatureParam = new SQLiteParameter("@signature", DbType.Binary);

            dbAudioFeatureParam.Value = audioFeature.ToBytes();
            dbNameParam.Value = audioFeature.Name;
            dbDurationParam.Value = audioFeature.Duration;
            dbBitStringParam.Value = audioFeature.BitString;

            List<int> trackids = new List<int>();
            foreach(bool[] signature in audioFeature.Signatures) {

                trackids.Add(trackid);
                dbTrackIdParam.Value = trackid;
                dbSignatureParam.Value = BoolToByte(signature);

                IDbCommand dbcmd;
                lock (dbcon) {
                    dbcmd = dbcon.CreateCommand();
                }
                dbcmd.CommandText = "INSERT INTO mirage (trackid, audioFeature, name, duration, bitstring, signature) " +
                    "VALUES (@trackid, @audioFeature, @name, @duration, @bitstring, @signature)";
                dbcmd.Parameters.Add(dbTrackIdParam);
                dbcmd.Parameters.Add(dbAudioFeatureParam);
                dbcmd.Parameters.Add(dbNameParam);
                dbcmd.Parameters.Add(dbDurationParam);
                dbcmd.Parameters.Add(dbBitStringParam);
                dbcmd.Parameters.Add(dbSignatureParam);

                try {
                    dbcmd.ExecuteNonQuery();
                } catch (SQLiteException) {
                    continue;
                }

                trackid++;
            }

            return trackids.ToArray();
        }
Exemple #3
0
		/// <summary>
		/// Add a track to the database
		/// </summary>
		/// <param name="audioFeature">the audiofeature object</param>
		/// <returns>-1 if failed otherwise the track-id passed</returns>
		public int AddTrack(AudioFeature audioFeature)
		{
			IDbDataParameter dbAudioFeatureParam = new SQLiteParameter("@audioFeature", DbType.Binary);
			IDbDataParameter dbNameParam = new SQLiteParameter("@name", DbType.String);
			IDbDataParameter dbDurationParam = new SQLiteParameter("@duration", DbType.Int64);
			IDbDataParameter dbBitStringParam = new SQLiteParameter("@bitstring", DbType.String);
			
			IDbCommand dbcmd;
			lock (dbcon) {
				dbcmd = dbcon.CreateCommand();
			}
			dbcmd.CommandText = "INSERT INTO mirage (audioFeature, name, duration, bitstring) " +
				"VALUES (@audioFeature, @name, @duration, @bitstring); SELECT last_insert_rowid();";
			
			dbcmd.Parameters.Add(dbAudioFeatureParam);
			dbcmd.Parameters.Add(dbNameParam);
			dbcmd.Parameters.Add(dbDurationParam);
			dbcmd.Parameters.Add(dbBitStringParam);

			dbAudioFeatureParam.Value = audioFeature.ToBytes();
			dbNameParam.Value = audioFeature.Name;
			dbDurationParam.Value = audioFeature.Duration;
			dbBitStringParam.Value = audioFeature.BitString;
			
			int trackid = -1;
			try {
				dbcmd.Prepare();
				//dbcmd.ExecuteNonQuery();
				trackid = Convert.ToInt32(dbcmd.ExecuteScalar());
				dbcmd.Dispose();
			} catch (Exception) {
				return -1;
			}
			return trackid;
		}