1

I am creating a very simple database in C# which I use to store playlists and an overview of all my music. I want to make this C compatible in the future I plan to make this completely text based. The idea is that every text file is a table, and the contents are JSON format where every line of text is a record.

I don't want to have loose files for each database, so I was thinking about something like a zip file. I don't want to extract and compress every time I access a file. Is there someway I can use a stream reader/writer in C# on different files where windows only see one file?

I'm not completely convinced that this is the way to go. So I'm open to suggestions.

Update, Im currently messing around with the "Local database" item in C#. I never payed any atention to it. It could very well be the solution.

Update2, SQLite seems to be very simple. I have some experience with MySQL in the past with some php projects so that will give me a headstart.

Bas
  • 3
  • 5
  • As far as I remember, the Ionic.Zip library allows to manipulate compressed files, even from the compressed file itself. – Nahuel Ianni Jul 07 '16 at 13:06

2 Answers2

1

You want to use a file as a container containing different files? If so, there are a lot ways to accomplish this. These are techniques I used in the past:

  • Zip:

A compressed file, such as Zip is known to behave that way, can be used as a solution for your interest. It is capable to store virtual files. They can vary in size to at least up to 1 Gigabyte (testet, but I currently don't know if there are implementation based size limits).

  • SQLite:

SQLite sounds oldschool, but it stores all database related stuff into one physical file. Creating a database with tables for each virtual file should to the trick. This approach is useful if you know that your virtual files won't use a lot of bytes in size or neither reach any limit of sqlite field datatypes. As your virtual files are going to use textlines, may you can be able to form then into attributes and tuples. This way you can even use SQL specific statements to query and filter your data as you wish to.

There are still more ways to implement that kind of container format by your own, but propably needs to invest more time and work in it than getting effort out of it. Stay tuned for better ideas and may ready to use implementations :-)

  • I have done some mysql in the past, so I think that is the way to go for me. But I don't want to use an extra server. – Bas Jul 07 '16 at 13:23
  • For your comfort, sqlite is well supported by this community and by foreign libraries, that should ease your step into sqlite – Gökhan Karabulut Jul 07 '16 at 13:27
  • Well, I think that SQLite is the best choice for my application. But what package should I download? I want this to work on both x86 and x64 systems. Also, I prefer no install. [SQLite download page](http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki) – Bas Jul 07 '16 at 14:07
  • This post should handle your upcoming problem with architecture: [link](http://stackoverflow.com/questions/19623823/sqlite-with-vs2012-and-net-4-5-any-cpu-build) – Gökhan Karabulut Jul 07 '16 at 14:18
  • Nuget isn't working for me. I'm still running C#2008 (Perhaps its time for an upgrade :)) – Bas Jul 07 '16 at 16:02
0

Will you ever try to search between your data? Then use a real database manager, in C# the built in local database file is the simpliest choice (if you are familiar with SQL). The zip file is a good choice for data space and compactness (a single file instead of many files) but it is very slow: for each database operation the whole zip file will be reorganized. Even a tar file (without compression) needs a continous reallocation when the content changes, and a zip file needs extra computation and relocation. If you want something what is compressed and still standard, you can use OpenXML (ods or xlsx, does not matter) to store your data but the save operation will be slow and even slower as your database grows.

Peter Krassoi
  • 571
  • 3
  • 11
  • I think that the C# build in database is the best for my application. The only drawback is that it is not very easely converted to use with plain C. – Bas Jul 07 '16 at 13:25