*************************************** * JDB DataBase System Documentation * * v 1.0 * *************************************** This is the documentation file of the JDB DataBase System, which explains how to use it with examples and more. === Info & Trivia === # Why did you create this? I wanted to create a database bank which I could use for managing my books and movies. As a test. Unafortunetly I didn't understand my code, it worked buggy... It was a LOT of work. So I started to create my own DataBase class from scratch. # Is there a hard-limit for the max size of the database? Yes. Everything is managed by Int32s(default integers), so if you pass at either the columns or rows with 2,147,483,647, you'll get errors. So DON'T create a data- base with more than 2 milion rows. Of course you can edit this. # Is it nice code? That's up to you. I don't know. But you can # Can I add another column without messing-up my database? No, you can't. It's not support and not tested. You can however edit this code to do that. See also "how it works" # Can I use any file extension? Yes! You can. # Did you test this? Yes, I tested this. I've tried to find & fix as many bugs as possible, yet there are maybe bugs. Overall the system works properly, and everything I've found is fixed. === How it === === works === Here's an example database: #name #note # year "Piet","derpina was derp","2011" "Loes","derpina WASN'T!!!","2012" "Anna","#hookchar#","2012" The columns are splitted with a ',', in code called SplitCharacter(default a space), which is useless after all. and the content is marked with a '"', in code called HookCharacter. If you want a that char in your column, it'll automaticly be replaced with "#hookchar#", so no errors are caused. The same for #nlchar#, it replaces the newline. The rows are stored in an array, and the rows itself is also an array, so you get string[row][column]. Note: Everything is zero-based(which you may know). so if I want to get the not of piet I do this: datbase.Rows[0][1], not this: databas.Rows[1][2]. === Usage === The class has these public accesible variables: - Rows : string[][] rows - Lines : string[] lines in file - Path : string path to file - Columns : string[] columns - HookCharacter : char - SplitCharacter: char - RowLength : int Lines.Length - ColumnLength : int Columns.Length It's handy if you manage your columns by the order you display them. It's easier to remember dimensions, thought you don't need to remember them thanks to some methods. I am not going to document every method. Why? Because I am REALLY bad at documenting and I don't like it at all. Anyways let's start with string[][] getRows(3 overloads): getRows(string[][] data, int columnLength, int index = -1, string arg = "", bool ignoreCase = false, bool getContaining = false) This searches for the rows with the same (containing) text. Like SELECT * FROM. The data is the table. arg is what you need to search. It returns another table, with only the results. The overloads do not contain the data and columnLength variables. In one overload you can give instead of the index the name of the column. Like this: getRows("Name", "Piet", true, false); string[] getListBoxStrings(int dimension = 0, string[][] data) With this method you can do awesome things. It gets all rows with only one column, to display for for example a ListBox. The dimension argument is which column. The data thinggy is awesome AND optional. With that argument you can do this with another table. --- Other methods --- readFile() - use this for reloading your database. getRowIndex(string[] data) - get's the index of the row you specified. Buggy. int getIndex(string column, bool ignoreCase = false) - Get's the index of an column. edit(int where, string[] data) - Edit's a row. remove(int where) - Removes a row remove(int[] where) - Removes multiple rows bool exists(...) - Checks if a row exists. Deprecated. === How to === === Implement === Well, first you need to create a new database. Simply follow the constructors arguments. The first agrument is the filename. It could be anything! The second argument are the columns. DataBase db = new DataBase("books.txt", new string[] { "Name", "Author" }); Now, we want some books in our database! db.add(new string[] { "C# in a nutshell", "Microsoft" }); db.add(new string[] { "Everyone likes ketchup", "him" }); db.add(new string[] { "Get rid of snakes", "dr. John" }); Ok, I need to search one book but I am REALLY lazy. string[][] data = db.getRows("Name", "C#", false, true); It'll return the first book. Congratulations! You just created a database! === Downloads === View http://joppiesaus.function1/dl/jdb/ for more info! === CHANGELOG === v 1.0.1(1-3-2014): - Fixed typo that caused "The search lower-case" bug. - Not mentioned in the class it self. v 1.0(28-2-2014) - Inital release === LICENSE === It's public domain! Thought I'd like some credit if you use it for your program, just my name hidden somewhere. I hope you found this usefull. Have fun coding! - joppiesaus