Searching via SDBApplication?

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Searching via SDBApplication?

Re: Searching via SDBApplication?

by Scottes » Fri Jan 30, 2015 6:31 pm

Here's one way using OpenSQL

Code: Select all

public static List<SongInfo> GetAllSongInfo(string artist, string album)
{
    var allSongInfo = new List<SongInfo>();

    string query = string.Format("SELECT * FROM Songs WHERE AlbumArtist LIKE '{0}' AND Album LIKE '{1}';", artist, album);

    var sdb = new SongsDB.SDBApplication();
    var queryData = sdb.Database.OpenSQL(query);
    while (true)
    {
        if (queryData.StringByName("ID") == null)
            break;

        var songInfo = new SongInfo();
        songInfo.Album = queryData.StringByName("Album");
        songInfo.AlbumArtist = queryData.StringByName("AlbumArtist");
        songInfo.Artist = queryData.StringByName("Artist");
        songInfo.Custom1 = queryData.StringByName("Custom1");
        songInfo.Custom2 = queryData.StringByName("Custom2");
        songInfo.Custom3 = queryData.StringByName("Custom3");
        songInfo.Custom4 = queryData.StringByName("Custom4");
        songInfo.Custom5 = queryData.StringByName("Custom5");
        songInfo.DateAdded = Convert.ToDouble(queryData.StringByName("DateAdded"));
        songInfo.Extension = queryData.StringByName("Extension");
        songInfo.FileModified = queryData.StringByName("FileModified");
        songInfo.Genre = queryData.StringByName("Genre");
        songInfo.Rating = Convert.ToInt32(queryData.StringByName("Rating"));
        songInfo.ID = Convert.ToInt32(queryData.StringByName("ID"));
        songInfo.SongLength = Convert.ToInt32(queryData.StringByName("SongLength"));
        songInfo.SongTitle = queryData.StringByName("SongTitle");
        songInfo.Year = Convert.ToInt32(queryData.StringByName("Year"));
        songInfo.SongPath = "C" + queryData.StringByName("SongPath");
        allSongInfo.Add(songInfo);

        queryData.Next();
    }
    sdb = null;

    return allSongInfo;
}

public struct SongInfo
{
    public string Album;
    public string AlbumArtist;
    public string Artist;
    public string Custom1;
    public string Custom2;
    public string Custom3;
    public string Custom4;
    public string Custom5;
    public double DateAdded;
    public string Extension;
    public string FileModified;
    public string Genre;
    public int Rating;
    public int ID;
    public int SongLength;
    public string SongPath;
    public string SongTitle;
    public int Year;            // Dec 13, 1997 stored as 19971213, ie; YYYYMMDD. Displayed as "12/13/1997"
    public string DiscogsID;
    public string DiscogsReleased;
    public string DiscogsArtistURL;
    public string DiscogsReleaseURL;
}

Re: Searching via SDBApplication?

by mcow » Sat Jan 17, 2015 12:27 pm

The element SDB.Database gets you an SDBDatabase object.
You need to learn how to construct an SQL query, and submit the query to the database.

Searching via SDBApplication?

by dharmaturtle » Sun Jan 11, 2015 10:50 pm

Hi, I'm a newbie C# programmer, so I'm still exploring what may be obvious things.

I can't seem to find a way to search an entire library via SDBApplication. I'm making a WPF application to help me organize my music (press this button to mark track as reviewed, press another button to combine these two playcounts favoring the one with the higher bitrate, make sure the song doesn't belong in any playlists, etc.)

I currently have an AutoPlaylist called "All" that contains my entire library. To search, I do this:

Code: Select all

AllSongs = MakeSongListEnumerable(SDB.PlaylistByTitle["All"].Tracks);

//============//

public static List<SDBSongData> MakeSongListEnumerable(SDBSongList songlist) {
  var selectedSongList = new List<SDBSongData>();
  foreach (var i in Enumerable.Range(0, songlist.Count)) {
    selectedSongList.Add(songlist.Item[i]);
  }
  return selectedSongList;
}
I iterate over every song in my library and shove it into a list and search through that. This obviously takes forever with large libraries (like mine), so could someone point me towards the actual search API?

I thought WebSearch was it, but I can't seem to understand it.

Thanks!

Top