Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hack Forums
- C# version of SQLiteHandler.vb ? - Printable Version
- +- Hack Forums (https://hackforums.net)
- +-- Forum: Programming, Coding, and Languages (https://hackforums.net/forumdisplay.php?fid=151)
- +--- Forum: Visual Basic and .NET Framework (https://hackforums.net/forumdisplay.php?fid=118)
- +---- Forum: C# Programming Language (https://hackforums.net/forumdisplay.php?fid=208)
- +---- Thread: C# version of SQLiteHandler.vb ? (/showthread.php?tid=4059126)
- Pages: 1 2
- C# version of SQLiteHandler.vb ? - DarkN3ss61 - 02-14-2014
- Hey guys, does anyone know if there is a C# version of this?
- http://pastebin.com/QUFMaygS
- Or am I going to have to manually convert it? Because so far i haven't managed to find it, as well as when I tried to convert it i still get a few errors.
- -Thanks Dark.
- * - ShadowCloud - 02-14-2014
- (02-14-2014, 10:22 AM)DarkN3ss61 Wrote: Hey guys, does anyone know if there is a C# version of this?
- http://pastebin.com/QUFMaygS
- Or am I going to have to manually convert it? Because so far i haven't managed to find it, as well as when I tried to convert it i still get a few errors.
- -Thanks Dark.
- I can't recall seeing anything like that in my lifetime. Why the requirement for not having the dependency?
- * - maarten1012 - 02-14-2014
- Don't know if this works, but I quickly converted it:
- Code
- using Microsoft.VisualBasic;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Diagnostics;
- //******
- //
- // Coded By: RockingWithTheBest
- //
- // v 0.1
- //
- //
- // A Handler for SQLite without needing the sqlite3.dll!
- // You can read every table and value from database, but
- // there is no support for input. Also no support for
- // journal files and overflow pages, maybe i will add
- // that in a later release.
- //
- //
- // Have Fun!
- //
- // If u want to learn more about or enhance it then visit:
- // http://www.sqlite.org/fileformat.html
- //
- // If you copy or modify it, please add me to credits!
- //
- // Questions etc. to: peterrlustig@googlemail.com
- //
- //******
- //
- // Example:
- //
- // Dim SQLDatabase = New SQLiteHandler("C:\Temp\Login Data")
- // SQLDatabase.ReadTable("logins")
- //
- // MsgBox(GetValue(SQLDatabase.GetValue(0, "username_value")))
- //
- //******
- using System.IO;
- public class SQLiteHandler
- {
- private byte[] db_bytes;
- private UInt16 page_size;
- private UInt64 encoding;
- private sqlite_master_entry[] master_table_entries;
- private byte[] SQLDataTypeSize = new byte[] {
- 0,
- 1,
- 2,
- 3,
- 4,
- 6,
- 8,
- 8,
- 0,
- 0
- };
- private table_entry[] table_entries;
- private string[] field_names;
- private struct record_header_field
- {
- public Int64 size;
- public Int64 type;
- }
- private struct table_entry
- {
- public Int64 row_id;
- public string[] content;
- }
- private struct sqlite_master_entry
- {
- public Int64 row_id;
- public string item_type;
- public string item_name;
- public string astable_name;
- public Int64 root_num;
- public string sql_statement;
- }
- //Needs BigEndian
- //GetVariableLength
- // returns the endindex of an variable length integer
- private int GVL(int startIndex)
- {
- if (startIndex > db_bytes.Length)
- return null;
- for (i = startIndex; i <= startIndex + 8; i += 1) {
- if (i > db_bytes.Length - 1) {
- return null;
- } else if ((db_bytes(i) & 0x80) != 0x80) {
- return i;
- }
- }
- return startIndex + 8;
- }
- // Eingaberichtung BigEndian
- // ConvertVariableLength
- private Int64 CVL(int startIndex, int endIndex)
- {
- endIndex = endIndex + 1;
- byte[] retus = new byte[8];
- dynamic Length = endIndex - startIndex;
- bool Bit64 = false;
- if (Length == 0 | Length > 9)
- return null;
- if (Length == 1) {
- retus(0) = (db_bytes(startIndex) & 0x7f);
- return BitConverter.ToInt64(retus, 0);
- }
- if (Length == 9) {
- // Ein Byte wird nämlich grad hinzugefügt
- Bit64 = true;
- }
- int j = 1;
- int k = 7;
- int y = 0;
- if (Bit64) {
- retus(0) = db_bytes(endIndex - 1);
- endIndex = endIndex - 1;
- y = 1;
- }
- for (i = (endIndex - 1); i >= startIndex; i += -1) {
- if ((i - 1) >= startIndex) {
- retus(y) = ((db_bytes(i) >> (j - 1)) & (0xff >> j)) | (db_bytes(i - 1) << k);
- j = j + 1;
- y = y + 1;
- k = k - 1;
- } else {
- if (!Bit64)
- retus(y) = ((db_bytes(i) >> (j - 1)) & (0xff >> j));
- }
- }
- return BitConverter.ToInt64(retus, 0);
- }
- //Checks if a number is odd
- private bool IsOdd(Int64 value)
- {
- return (value & 1) == 1;
- }
- //Big Endian Conversation
- private UInt64 ConvertToInteger(int startIndex, int Size)
- {
- if (Size > 8 | Size == 0)
- return null;
- UInt64 retVal = 0;
- for (i = 0; i <= Size - 1; i += 1) {
- retVal = ((retVal << 8) | db_bytes(startIndex + i));
- }
- return retVal;
- }
- private void ReadMasterTable(UInt64 Offset)
- {
- //Leaf node
- if (db_bytes(Offset) == 0xd) {
- //Length for setting the array length for the entries
- UInt16 Length = ConvertToInteger(Offset + 3, 2) - 1;
- int ol = 0;
- if ((master_table_entries != null)) {
- ol = master_table_entries.Length;
- Array.Resize(ref master_table_entries, master_table_entries.Length + Length + 1);
- } else {
- master_table_entries = new sqlite_master_entry[Length + 1];
- }
- UInt64 ent_offset = default(UInt64);
- for (i = 0; i <= Length; i += 1) {
- ent_offset = ConvertToInteger(Offset + 8 + (i * 2), 2);
- if (Offset != 100)
- ent_offset = ent_offset + Offset;
- //Table Cell auslesen
- dynamic t = GVL(ent_offset);
- Int64 size = CVL(ent_offset, t);
- dynamic s = GVL(ent_offset + (t - ent_offset) + 1);
- master_table_entries(ol + i).row_id = CVL(ent_offset + (t - ent_offset) + 1, s);
- //Table Content
- //Resetting the offset
- ent_offset = ent_offset + (s - ent_offset) + 1;
- //Now get to the Record Header
- t = GVL(ent_offset);
- s = t;
- Int64 Rec_Header_Size = CVL(ent_offset, t);
- //Record Header Length
- Int64[] Field_Size = new Int64[5];
- //Now get the field sizes and fill in the Values
- for (j = 0; j <= 4; j += 1) {
- t = s + 1;
- s = GVL(t);
- Field_Size(j) = CVL(t, s);
- if (Field_Size(j) > 9) {
- if (IsOdd(Field_Size(j))) {
- Field_Size(j) = (Field_Size(j) - 13) / 2;
- } else {
- Field_Size(j) = (Field_Size(j) - 12) / 2;
- }
- } else {
- Field_Size(j) = SQLDataTypeSize(Field_Size(j));
- }
- }
- // Wir lesen nur unbedingt notwendige Sachen aus
- if (encoding == 1) {
- master_table_entries(ol + i).item_type = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size, Field_Size(0));
- } else if (encoding == 2) {
- master_table_entries(ol + i).item_type = System.Text.Encoding.Unicode.GetString(db_bytes, ent_offset + Rec_Header_Size, Field_Size(0));
- } else if (encoding == 3) {
- master_table_entries(ol + i).item_type = System.Text.Encoding.BigEndianUnicode.GetString(db_bytes, ent_offset + Rec_Header_Size, Field_Size(0));
- }
- if (encoding == 1) {
- master_table_entries(ol + i).item_name = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0), Field_Size(1));
- } else if (encoding == 2) {
- master_table_entries(ol + i).item_name = System.Text.Encoding.Unicode.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0), Field_Size(1));
- } else if (encoding == 3) {
- master_table_entries(ol + i).item_name = System.Text.Encoding.BigEndianUnicode.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0), Field_Size(1));
- }
- //master_table_entries(ol + i).astable_name = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1), Field_Size(2))
- master_table_entries(ol + i).root_num = ConvertToInteger(ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1) + Field_Size(2), Field_Size(3));
- if (encoding == 1) {
- master_table_entries(ol + i).sql_statement = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1) + Field_Size(2) + Field_Size(3), Field_Size(4));
- } else if (encoding == 2) {
- master_table_entries(ol + i).sql_statement = System.Text.Encoding.Unicode.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1) + Field_Size(2) + Field_Size(3), Field_Size(4));
- } else if (encoding == 3) {
- master_table_entries(ol + i).sql_statement = System.Text.Encoding.BigEndianUnicode.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1) + Field_Size(2) + Field_Size(3), Field_Size(4));
- }
- }
- //internal node
- } else if (db_bytes(Offset) == 0x5) {
- UInt16 Length = ConvertToInteger(Offset + 3, 2) - 1;
- UInt16 ent_offset = default(UInt16);
- for (i = 0; i <= Length; i += 1) {
- ent_offset = ConvertToInteger(Offset + 12 + (i * 2), 2);
- if (Offset == 100) {
- ReadMasterTable((ConvertToInteger(ent_offset, 4) - 1) * page_size);
- } else {
- ReadMasterTable((ConvertToInteger(Offset + ent_offset, 4) - 1) * page_size);
- }
- }
- ReadMasterTable((ConvertToInteger(Offset + 8, 4) - 1) * page_size);
- }
- }
- private bool ReadTableFromOffset(UInt64 Offset)
- {
- //Leaf node
- if (db_bytes(Offset) == 0xd) {
- //Length for setting the array length for the entries
- UInt16 Length = ConvertToInteger(Offset + 3, 2) - 1;
- int ol = 0;
- if ((table_entries != null)) {
- ol = table_entries.Length;
- Array.Resize(ref table_entries, table_entries.Length + Length + 1);
- } else {
- table_entries = new table_entry[Length + 1];
- }
- UInt64 ent_offset = default(UInt64);
- for (i = 0; i <= Length; i += 1) {
- ent_offset = ConvertToInteger(Offset + 8 + (i * 2), 2);
- if (Offset != 100)
- ent_offset = ent_offset + Offset;
- //Table Cell auslesen
- dynamic t = GVL(ent_offset);
- Int64 size = CVL(ent_offset, t);
- dynamic s = GVL(ent_offset + (t - ent_offset) + 1);
- table_entries(ol + i).row_id = CVL(ent_offset + (t - ent_offset) + 1, s);
- //Table Content
- //Resetting the offset
- ent_offset = ent_offset + (s - ent_offset) + 1;
- //Now get to the Record Header
- t = GVL(ent_offset);
- s = t;
- Int64 Rec_Header_Size = CVL(ent_offset, t);
- //Record Header Length
- record_header_field[] Field_Size = null;
- Int64 size_read = (ent_offset - t) + 1;
- dynamic j = 0;
- //Now get the field sizes and fill in the Values
- while (size_read < Rec_Header_Size) {
- Array.Resize(ref Field_Size, j + 1);
- t = s + 1;
- s = GVL(t);
- Field_Size(j).type = CVL(t, s);
- if (Field_Size(j).type > 9) {
- if (IsOdd(Field_Size(j).type)) {
- Field_Size(j).size = (Field_Size(j).type - 13) / 2;
- } else {
- Field_Size(j).size = (Field_Size(j).type - 12) / 2;
- }
- } else {
- Field_Size(j).size = SQLDataTypeSize(Field_Size(j).type);
- }
- size_read = size_read + (s - t) + 1;
- j = j + 1;
- }
- // ERROR: Not supported in C#: ReDimStatement
- int counter = 0;
- for (k = 0; k <= Field_Size.Length - 1; k += 1) {
- if (Field_Size(k).type > 9) {
- if (!IsOdd(Field_Size(k).type)) {
- if (encoding == 1) {
- table_entries(ol + i).content(k) = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + counter, Field_Size(k).size);
- } else if (encoding == 2) {
- table_entries(ol + i).content(k) = System.Text.Encoding.Unicode.GetString(db_bytes, ent_offset + Rec_Header_Size + counter, Field_Size(k).size);
- } else if (encoding == 3) {
- table_entries(ol + i).content(k) = System.Text.Encoding.BigEndianUnicode.GetString(db_bytes, ent_offset + Rec_Header_Size + counter, Field_Size(k).size);
- }
- } else {
- table_entries(ol + i).content(k) = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + counter, Field_Size(k).size);
- }
- } else {
- table_entries(ol + i).content(k) = Convert.ToString(ConvertToInteger(ent_offset + Rec_Header_Size + counter, Field_Size(k).size));
- }
- counter = counter + Field_Size(k).size;
- }
- }
- //internal node
- } else if (db_bytes(Offset) == 0x5) {
- UInt16 Length = ConvertToInteger(Offset + 3, 2) - 1;
- UInt16 ent_offset = default(UInt16);
- for (i = 0; i <= Length; i += 1) {
- ent_offset = ConvertToInteger(Offset + 12 + (i * 2), 2);
- ReadTableFromOffset((ConvertToInteger(Offset + ent_offset, 4) - 1) * page_size);
- }
- ReadTableFromOffset((ConvertToInteger(Offset + 8, 4) - 1) * page_size);
- }
- return true;
- }
- // Reads a complete table with all entries in it
- public bool ReadTable(string TableName)
- {
- // First loop through sqlite_master and look if table exists
- int found = -1;
- for (i = 0; i <= master_table_entries.Length; i += 1) {
- if (master_table_entries(i).item_name.ToLower().CompareTo(TableName.ToLower()) == 0) {
- found = i;
- break; // TODO: might not be correct. Was : Exit For
- }
- }
- if (found == -1)
- return false;
- [] fields = master_table_entries(found).sql_statement.Substring(master_table_entries(found).sql_statement.IndexOf("(") + 1).Split(",");
- for (i = 0; i <= fields.Length - 1; i += 1) {
- fields(i) = Strings.LTrim(fields(i));
- dynamic index = fields(i).IndexOf(" ");
- if (index > 0)
- fields(i) = fields(i).Substring(0, index);
- if (fields(i).IndexOf("UNIQUE") == 0) {
- break; // TODO: might not be correct. Was : Exit For
- } else {
- Array.Resize(ref field_names, i + 1);
- field_names(i) = fields(i);
- }
- }
- return ReadTableFromOffset((master_table_entries(found).root_num - 1) * page_size);
- }
- // Returns the row count of current table
- public int GetRowCount()
- {
- return table_entries.Length;
- }
- // Returns a Value from current table in row row_num with field number field
- public string GetValue(int row_num, int field)
- {
- if (row_num >= table_entries.Length)
- return null;
- if (field >= table_entries(row_num).content.Length)
- return null;
- return table_entries(row_num).content(field);
- }
- // Returns a Value from current table in row row_num with field name field
- public string GetValue(int row_num, string field)
- {
- int found = -1;
- for (i = 0; i <= field_names.Length; i += 1) {
- if (field_names(i).ToLower().CompareTo(field.ToLower()) == 0) {
- found = i;
- break; // TODO: might not be correct. Was : Exit For
- }
- }
- if (found == -1)
- return null;
- return GetValue(row_num, found);
- }
- // Returns a String-Array with all Tablenames
- public string[] GetTableNames()
- {
- string[] retVal = null;
- dynamic arr = 0;
- for (i = 0; i <= master_table_entries.Length - 1; i += 1) {
- if (master_table_entries(i).item_type == "table") {
- Array.Resize(ref retVal, arr + 1);
- retVal(arr) = master_table_entries(i).item_name;
- arr = arr + 1;
- }
- }
- return retVal;
- }
- // Constructor
- public SQLiteHandler(string baseName)
- {
- //Page Number n is page_size*(n-1)
- if (File.Exists(baseName)) {
- FileSystem.FileOpen(1, baseName, OpenMode.Binary, OpenAccess.Read, OpenShare.Shared);
- string asi = Strings.Space(FileSystem.LOF(1));
- FileSystem.FileGet(1, asi);
- FileSystem.FileClose(1);
- db_bytes = System.Text.Encoding.Default.GetBytes(asi);
- if (System.Text.Encoding.Default.GetString(db_bytes, 0, 15).CompareTo("SQLite format 3") != 0) {
- throw new Exception("Not a valid SQLite 3 Database File");
- System.Environment.Exit(0);
- }
- if (db_bytes(52) != 0) {
- throw new Exception("Auto-vacuum capable database is not supported");
- System.Environment.Exit(0);
- } else if (ConvertToInteger(44, 4) >= 4) {
- throw new Exception("No supported Schema layer file-format");
- System.Environment.Exit(0);
- }
- page_size = ConvertToInteger(16, 2);
- encoding = ConvertToInteger(56, 4);
- if (encoding == 0)
- encoding = 1;
- //Now we read the sqlite_master table
- //Offset is 100 in first page
- ReadMasterTable(100);
- }
- }
- }
- //======
- //Service provided by Telerik (www.telerik.com)
- //Conversion powered by NRefactory.
- //Twitter: @telerik
- //Facebook: facebook.com/telerik
- //======
- * - DarkN3ss61 - 02-14-2014
- (02-14-2014, 11:14 AM)maarten1012 Wrote: Don't know if this works, but I quickly converted it:
- Code
- using Microsoft.VisualBasic;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Diagnostics;
- //******
- //
- // Coded By: RockingWithTheBest
- //
- // v 0.1
- //
- //
- // A Handler for SQLite without needing the sqlite3.dll!
- // You can read every table and value from database, but
- // there is no support for input. Also no support for
- // journal files and overflow pages, maybe i will add
- // that in a later release.
- //
- //
- // Have Fun!
- //
- // If u want to learn more about or enhance it then visit:
- // http://www.sqlite.org/fileformat.html
- //
- // If you copy or modify it, please add me to credits!
- //
- // Questions etc. to: peterrlustig@googlemail.com
- //
- //******
- //
- // Example:
- //
- // Dim SQLDatabase = New SQLiteHandler("C:\Temp\Login Data")
- // SQLDatabase.ReadTable("logins")
- //
- // MsgBox(GetValue(SQLDatabase.GetValue(0, "username_value")))
- //
- //******
- using System.IO;
- public class SQLiteHandler
- {
- private byte[] db_bytes;
- private UInt16 page_size;
- private UInt64 encoding;
- private sqlite_master_entry[] master_table_entries;
- private byte[] SQLDataTypeSize = new byte[] {
- 0,
- 1,
- 2,
- 3,
- 4,
- 6,
- 8,
- 8,
- 0,
- 0
- };
- private table_entry[] table_entries;
- private string[] field_names;
- private struct record_header_field
- {
- public Int64 size;
- public Int64 type;
- }
- private struct table_entry
- {
- public Int64 row_id;
- public string[] content;
- }
- private struct sqlite_master_entry
- {
- public Int64 row_id;
- public string item_type;
- public string item_name;
- public string astable_name;
- public Int64 root_num;
- public string sql_statement;
- }
- //Needs BigEndian
- //GetVariableLength
- // returns the endindex of an variable length integer
- private int GVL(int startIndex)
- {
- if (startIndex > db_bytes.Length)
- return null;
- for (i = startIndex; i <= startIndex + 8; i += 1) {
- if (i > db_bytes.Length - 1) {
- return null;
- } else if ((db_bytes(i) & 0x80) != 0x80) {
- return i;
- }
- }
- return startIndex + 8;
- }
- // Eingaberichtung BigEndian
- // ConvertVariableLength
- private Int64 CVL(int startIndex, int endIndex)
- {
- endIndex = endIndex + 1;
- byte[] retus = new byte[8];
- dynamic Length = endIndex - startIndex;
- bool Bit64 = false;
- if (Length == 0 | Length > 9)
- return null;
- if (Length == 1) {
- retus(0) = (db_bytes(startIndex) & 0x7f);
- return BitConverter.ToInt64(retus, 0);
- }
- if (Length == 9) {
- // Ein Byte wird nämlich grad hinzugefügt
- Bit64 = true;
- }
- int j = 1;
- int k = 7;
- int y = 0;
- if (Bit64) {
- retus(0) = db_bytes(endIndex - 1);
- endIndex = endIndex - 1;
- y = 1;
- }
- for (i = (endIndex - 1); i >= startIndex; i += -1) {
- if ((i - 1) >= startIndex) {
- retus(y) = ((db_bytes(i) >> (j - 1)) & (0xff >> j)) | (db_bytes(i - 1) << k);
- j = j + 1;
- y = y + 1;
- k = k - 1;
- } else {
- if (!Bit64)
- retus(y) = ((db_bytes(i) >> (j - 1)) & (0xff >> j));
- }
- }
- return BitConverter.ToInt64(retus, 0);
- }
- //Checks if a number is odd
- private bool IsOdd(Int64 value)
- {
- return (value & 1) == 1;
- }
- //Big Endian Conversation
- private UInt64 ConvertToInteger(int startIndex, int Size)
- {
- if (Size > 8 | Size == 0)
- return null;
- UInt64 retVal = 0;
- for (i = 0; i <= Size - 1; i += 1) {
- retVal = ((retVal << 8) | db_bytes(startIndex + i));
- }
- return retVal;
- }
- private void ReadMasterTable(UInt64 Offset)
- {
- //Leaf node
- if (db_bytes(Offset) == 0xd) {
- //Length for setting the array length for the entries
- UInt16 Length = ConvertToInteger(Offset + 3, 2) - 1;
- int ol = 0;
- if ((master_table_entries != null)) {
- ol = master_table_entries.Length;
- Array.Resize(ref master_table_entries, master_table_entries.Length + Length + 1);
- } else {
- master_table_entries = new sqlite_master_entry[Length + 1];
- }
- UInt64 ent_offset = default(UInt64);
- for (i = 0; i <= Length; i += 1) {
- ent_offset = ConvertToInteger(Offset + 8 + (i * 2), 2);
- if (Offset != 100)
- ent_offset = ent_offset + Offset;
- //Table Cell auslesen
- dynamic t = GVL(ent_offset);
- Int64 size = CVL(ent_offset, t);
- dynamic s = GVL(ent_offset + (t - ent_offset) + 1);
- master_table_entries(ol + i).row_id = CVL(ent_offset + (t - ent_offset) + 1, s);
- //Table Content
- //Resetting the offset
- ent_offset = ent_offset + (s - ent_offset) + 1;
- //Now get to the Record Header
- t = GVL(ent_offset);
- s = t;
- Int64 Rec_Header_Size = CVL(ent_offset, t);
- //Record Header Length
- Int64[] Field_Size = new Int64[5];
- //Now get the field sizes and fill in the Values
- for (j = 0; j <= 4; j += 1) {
- t = s + 1;
- s = GVL(t);
- Field_Size(j) = CVL(t, s);
- if (Field_Size(j) > 9) {
- if (IsOdd(Field_Size(j))) {
- Field_Size(j) = (Field_Size(j) - 13) / 2;
- } else {
- Field_Size(j) = (Field_Size(j) - 12) / 2;
- }
- } else {
- Field_Size(j) = SQLDataTypeSize(Field_Size(j));
- }
- }
- // Wir lesen nur unbedingt notwendige Sachen aus
- if (encoding == 1) {
- master_table_entries(ol + i).item_type = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size, Field_Size(0));
- } else if (encoding == 2) {
- master_table_entries(ol + i).item_type = System.Text.Encoding.Unicode.GetString(db_bytes, ent_offset + Rec_Header_Size, Field_Size(0));
- } else if (encoding == 3) {
- master_table_entries(ol + i).item_type = System.Text.Encoding.BigEndianUnicode.GetString(db_bytes, ent_offset + Rec_Header_Size, Field_Size(0));
- }
- if (encoding == 1) {
- master_table_entries(ol + i).item_name = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0), Field_Size(1));
- } else if (encoding == 2) {
- master_table_entries(ol + i).item_name = System.Text.Encoding.Unicode.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0), Field_Size(1));
- } else if (encoding == 3) {
- master_table_entries(ol + i).item_name = System.Text.Encoding.BigEndianUnicode.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0), Field_Size(1));
- }
- //master_table_entries(ol + i).astable_name = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1), Field_Size(2))
- master_table_entries(ol + i).root_num = ConvertToInteger(ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1) + Field_Size(2), Field_Size(3));
- if (encoding == 1) {
- master_table_entries(ol + i).sql_statement = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1) + Field_Size(2) + Field_Size(3), Field_Size(4));
- } else if (encoding == 2) {
- master_table_entries(ol + i).sql_statement = System.Text.Encoding.Unicode.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1) + Field_Size(2) + Field_Size(3), Field_Size(4));
- } else if (encoding == 3) {
- master_table_entries(ol + i).sql_statement = System.Text.Encoding.BigEndianUnicode.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1) + Field_Size(2) + Field_Size(3), Field_Size(4));
- }
- }
- //internal node
- } else if (db_bytes(Offset) == 0x5) {
- UInt16 Length = ConvertToInteger(Offset + 3, 2) - 1;
- UInt16 ent_offset = default(UInt16);
- for (i = 0; i <= Length; i += 1) {
- ent_offset = ConvertToInteger(Offset + 12 + (i * 2), 2);
- if (Offset == 100) {
- ReadMasterTable((ConvertToInteger(ent_offset, 4) - 1) * page_size);
- } else {
- ReadMasterTable((ConvertToInteger(Offset + ent_offset, 4) - 1) * page_size);
- }
- }
- ReadMasterTable((ConvertToInteger(Offset + 8, 4) - 1) * page_size);
- }
- }
- private bool ReadTableFromOffset(UInt64 Offset)
- {
- //Leaf node
- if (db_bytes(Offset) == 0xd) {
- //Length for setting the array length for the entries
- UInt16 Length = ConvertToInteger(Offset + 3, 2) - 1;
- int ol = 0;
- if ((table_entries != null)) {
- ol = table_entries.Length;
- Array.Resize(ref table_entries, table_entries.Length + Length + 1);
- } else {
- table_entries = new table_entry[Length + 1];
- }
- UInt64 ent_offset = default(UInt64);
- for (i = 0; i <= Length; i += 1) {
- ent_offset = ConvertToInteger(Offset + 8 + (i * 2), 2);
- if (Offset != 100)
- ent_offset = ent_offset + Offset;
- //Table Cell auslesen
- dynamic t = GVL(ent_offset);
- Int64 size = CVL(ent_offset, t);
- dynamic s = GVL(ent_offset + (t - ent_offset) + 1);
- table_entries(ol + i).row_id = CVL(ent_offset + (t - ent_offset) + 1, s);
- //Table Content
- //Resetting the offset
- ent_offset = ent_offset + (s - ent_offset) + 1;
- //Now get to the Record Header
- t = GVL(ent_offset);
- s = t;
- Int64 Rec_Header_Size = CVL(ent_offset, t);
- //Record Header Length
- record_header_field[] Field_Size = null;
- Int64 size_read = (ent_offset - t) + 1;
- dynamic j = 0;
- //Now get the field sizes and fill in the Values
- while (size_read < Rec_Header_Size) {
- Array.Resize(ref Field_Size, j + 1);
- t = s + 1;
- s = GVL(t);
- Field_Size(j).type = CVL(t, s);
- if (Field_Size(j).type > 9) {
- if (IsOdd(Field_Size(j).type)) {
- Field_Size(j).size = (Field_Size(j).type - 13) / 2;
- } else {
- Field_Size(j).size = (Field_Size(j).type - 12) / 2;
- }
- } else {
- Field_Size(j).size = SQLDataTypeSize(Field_Size(j).type);
- }
- size_read = size_read + (s - t) + 1;
- j = j + 1;
- }
- // ERROR: Not supported in C#: ReDimStatement
- int counter = 0;
- for (k = 0; k <= Field_Size.Length - 1; k += 1) {
- if (Field_Size(k).type > 9) {
- if (!IsOdd(Field_Size(k).type)) {
- if (encoding == 1) {
- table_entries(ol + i).content(k) = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + counter, Field_Size(k).size);
- } else if (encoding == 2) {
- table_entries(ol + i).content(k) = System.Text.Encoding.Unicode.GetString(db_bytes, ent_offset + Rec_Header_Size + counter, Field_Size(k).size);
- } else if (encoding == 3) {
- table_entries(ol + i).content(k) = System.Text.Encoding.BigEndianUnicode.GetString(db_bytes, ent_offset + Rec_Header_Size + counter, Field_Size(k).size);
- }
- } else {
- table_entries(ol + i).content(k) = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + counter, Field_Size(k).size);
- }
- } else {
- table_entries(ol + i).content(k) = Convert.ToString(ConvertToInteger(ent_offset + Rec_Header_Size + counter, Field_Size(k).size));
- }
- counter = counter + Field_Size(k).size;
- }
- }
- //internal node
- } else if (db_bytes(Offset) == 0x5) {
- UInt16 Length = ConvertToInteger(Offset + 3, 2) - 1;
- UInt16 ent_offset = default(UInt16);
- for (i = 0; i <= Length; i += 1) {
- ent_offset = ConvertToInteger(Offset + 12 + (i * 2), 2);
- ReadTableFromOffset((ConvertToInteger(Offset + ent_offset, 4) - 1) * page_size);
- }
- ReadTableFromOffset((ConvertToInteger(Offset + 8, 4) - 1) * page_size);
- }
- return true;
- }
- // Reads a complete table with all entries in it
- public bool ReadTable(string TableName)
- {
- // First loop through sqlite_master and look if table exists
- int found = -1;
- for (i = 0; i <= master_table_entries.Length; i += 1) {
- if (master_table_entries(i).item_name.ToLower().CompareTo(TableName.ToLower()) == 0) {
- found = i;
- break; // TODO: might not be correct. Was : Exit For
- }
- }
- if (found == -1)
- return false;
- [] fields = master_table_entries(found).sql_statement.Substring(master_table_entries(found).sql_statement.IndexOf("(") + 1).Split(",");
- for (i = 0; i <= fields.Length - 1; i += 1) {
- fields(i) = Strings.LTrim(fields(i));
- dynamic index = fields(i).IndexOf(" ");
- if (index > 0)
- fields(i) = fields(i).Substring(0, index);
- if (fields(i).IndexOf("UNIQUE") == 0) {
- break; // TODO: might not be correct. Was : Exit For
- } else {
- Array.Resize(ref field_names, i + 1);
- field_names(i) = fields(i);
- }
- }
- return ReadTableFromOffset((master_table_entries(found).root_num - 1) * page_size);
- }
- // Returns the row count of current table
- public int GetRowCount()
- {
- return table_entries.Length;
- }
- // Returns a Value from current table in row row_num with field number field
- public string GetValue(int row_num, int field)
- {
- if (row_num >= table_entries.Length)
- return null;
- if (field >= table_entries(row_num).content.Length)
- return null;
- return table_entries(row_num).content(field);
- }
- // Returns a Value from current table in row row_num with field name field
- public string GetValue(int row_num, string field)
- {
- int found = -1;
- for (i = 0; i <= field_names.Length; i += 1) {
- if (field_names(i).ToLower().CompareTo(field.ToLower()) == 0) {
- found = i;
- break; // TODO: might not be correct. Was : Exit For
- }
- }
- if (found == -1)
- return null;
- return GetValue(row_num, found);
- }
- // Returns a String-Array with all Tablenames
- public string[] GetTableNames()
- {
- string[] retVal = null;
- dynamic arr = 0;
- for (i = 0; i <= master_table_entries.Length - 1; i += 1) {
- if (master_table_entries(i).item_type == "table") {
- Array.Resize(ref retVal, arr + 1);
- retVal(arr) = master_table_entries(i).item_name;
- arr = arr + 1;
- }
- }
- return retVal;
- }
- // Constructor
- public SQLiteHandler(string baseName)
- {
- //Page Number n is page_size*(n-1)
- if (File.Exists(baseName)) {
- FileSystem.FileOpen(1, baseName, OpenMode.Binary, OpenAccess.Read, OpenShare.Shared);
- string asi = Strings.Space(FileSystem.LOF(1));
- FileSystem.FileGet(1, asi);
- FileSystem.FileClose(1);
- db_bytes = System.Text.Encoding.Default.GetBytes(asi);
- if (System.Text.Encoding.Default.GetString(db_bytes, 0, 15).CompareTo("SQLite format 3") != 0) {
- throw new Exception("Not a valid SQLite 3 Database File");
- System.Environment.Exit(0);
- }
- if (db_bytes(52) != 0) {
- throw new Exception("Auto-vacuum capable database is not supported");
- System.Environment.Exit(0);
- } else if (ConvertToInteger(44, 4) >= 4) {
- throw new Exception("No supported Schema layer file-format");
- System.Environment.Exit(0);
- }
- page_size = ConvertToInteger(16, 2);
- encoding = ConvertToInteger(56, 4);
- if (encoding == 0)
- encoding = 1;
- //Now we read the sqlite_master table
- //Offset is 100 in first page
- ReadMasterTable(100);
- }
- }
- }
- //======
- //Service provided by Telerik (www.telerik.com)
- //Conversion powered by NRefactory.
- //Twitter: @telerik
- //Facebook: facebook.com/telerik
- //======
- Thanks but it won't work because that's the same website I originally used to convert it and it still had quite a few errors. :/
- So just incase anyone could finish this off for me
- This is where im up to
- Code
- public class SQLiteHandler
- {
- private byte[] db_bytes;
- private UInt16 page_size;
- private UInt64 encoding;
- private sqlite_master_entry[] master_table_entries;
- private byte[] SQLDataTypeSize = new byte[] {0,1,2,3,4,6,8,8,0,0};
- private table_entry[] table_entries;
- private string[] field_names;
- private struct record_header_field
- {
- public Int64 size;
- public Int64 type;
- }
- private struct table_entry
- {
- public Int64 row_id;
- public string[] content;
- }
- private struct sqlite_master_entry
- {
- public Int64 row_id;
- public string item_type;
- public string item_name;
- public string astable_name;
- public Int64 root_num;
- public string sql_statement;
- }
- //Needs BigEndian
- //GetVariableLength
- // returns the endindex of an variable length integer
- private int GVL(int startIndex)
- {
- if (startIndex > db_bytes.Length)
- return 0;
- for (int i = startIndex; i <= startIndex + 8; i += 1)
- {
- if (i > db_bytes.Length - 1)
- {
- return 0;
- }
- else if ((db_bytes[i] & 0x80) != 0x80)
- {
- return i;
- }
- }
- return startIndex + 8;
- }
- // Eingaberichtung BigEndian
- // ConvertVariableLength
- private Int64 CVL(int startIndex, int endIndex)
- {
- endIndex = endIndex + 1;
- byte[] retus = new byte[8];
- dynamic Length = endIndex - startIndex;
- bool Bit64 = false;
- if (Length == 0 | Length > 9)
- return 0;
- if (Length == 1)
- {
- retus[0] = (db_bytes(startIndex) & 0x7f);
- return BitConverter.ToInt64(retus, 0);
- }
- if (Length == 9)
- {
- // Ein Byte wird nämlich grad hinzugefügt
- Bit64 = true;
- }
- int j = 1;
- int k = 7;
- int y = 0;
- if (Bit64)
- {
- retus[0] = db_bytes(endIndex - 1);
- endIndex = endIndex - 1;
- y = 1;
- }
- for (int i = (endIndex - 1); i >= startIndex; i += -1)
- {
- if ((i - 1) >= startIndex)
- {
- retus[y] = ((db_bytes(i) >> (j - 1)) & (0xff >> j)) | (db_bytes(i - 1) << k);
- j = j + 1;
- y = y + 1;
- k = k - 1;
- }
- else
- {
- if (!Bit64)
- retus[y] = ((db_bytes(i) >> (j - 1)) & (0xff >> j));
- }
- }
- return BitConverter.ToInt64(retus, 0);
- }
- //Checks if a number is odd
- private bool IsOdd(Int64 value)
- {
- return (value & 1) == 1;
- }
- //Big Endian Conversation
- private UInt64 ConvertToInteger(int startIndex, int Size)
- {
- if (Size > 8 | Size == 0)
- return 0;
- UInt64 retVal = 0;
- for (int i = 0; i <= Size - 1; i += 1)
- {
- retVal = ((retVal << 8) | db_bytes(startIndex + i));
- }
- return retVal;
- }
- private void ReadMasterTable(UInt64 Offset)
- {
- //Leaf node
- if (db_bytes(Offset) == 0xd)
- {
- //Length for setting the array length for the entries
- UInt16 Length = ConvertToInteger(Offset + 3, 2) - 1;
- int ol = 0;
- if ((master_table_entries != null))
- {
- ol = master_table_entries.Length;
- Array.Resize(ref master_table_entries, master_table_entries.Length + Length + 1);
- }
- else
- {
- master_table_entries = new sqlite_master_entry[Length + 1];
- }
- UInt64 ent_offset = default(UInt64);
- for (int i = 0; i <= Length; i += 1)
- {
- ent_offset = ConvertToInteger(Offset + 8 + (i * 2), 2);
- if (Offset != 100)
- ent_offset = ent_offset + Offset;
- //Table Cell auslesen
- dynamic t = GVL(ent_offset);
- Int64 size = CVL(ent_offset, t);
- dynamic s = GVL(ent_offset + (t - ent_offset) + 1);
- master_table_entries(ol + i).row_id = CVL(ent_offset + (t - ent_offset) + 1, s);
- //Table Content
- //Resetting the offset
- ent_offset = ent_offset + (s - ent_offset) + 1;
- //Now get to the Record Header
- t = GVL(ent_offset);
- s = t;
- Int64 Rec_Header_Size = CVL(ent_offset, t);
- //Record Header Length
- Int64[] Field_Size = new Int64[5];
- //Now get the field sizes and fill in the Values
- for (int j = 0; j <= 4; j += 1)
- {
- t = s + 1;
- s = GVL(t);
- Field_Size[j] = CVL(t, s);
- if (Field_Size[j] > 9)
- {
- if (IsOdd(Field_Size[j]))
- {
- Field_Size[j] = (Field_Size[j] - 13) / 2;
- }
- else
- {
- Field_Size[j] = (Field_Size[j] - 12) / 2;
- }
- }
- else
- {
- Field_Size[j] = SQLDataTypeSize(Field_Size[j]);
- }
- }
- // Wir lesen nur unbedingt notwendige Sachen aus
- if (encoding == 1)
- {
- master_table_entries(ol + i).item_type = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size, Field_Size(0));
- }
- else if (encoding == 2)
- {
- master_table_entries(ol + i).item_type = System.Text.Encoding.Unicode.GetString(db_bytes, ent_offset + Rec_Header_Size, Field_Size(0));
- }
- else if (encoding == 3)
- {
- master_table_entries(ol + i).item_type = System.Text.Encoding.BigEndianUnicode.GetString(db_bytes, ent_offset + Rec_Header_Size, Field_Size(0));
- }
- if (encoding == 1)
- {
- master_table_entries(ol + i).item_name = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0), Field_Size(1));
- }
- else if (encoding == 2)
- {
- master_table_entries(ol + i).item_name = System.Text.Encoding.Unicode.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0), Field_Size(1));
- }
- else if (encoding == 3)
- {
- master_table_entries(ol + i).item_name = System.Text.Encoding.BigEndianUnicode.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0), Field_Size(1));
- }
- //master_table_entries(ol + i).astable_name = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1), Field_Size(2))
- master_table_entries(ol + i).root_num = ConvertToInteger(ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1) + Field_Size(2), Field_Size(3));
- if (encoding == 1)
- {
- master_table_entries(ol + i).sql_statement = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1) + Field_Size(2) + Field_Size(3), Field_Size(4));
- }
- else if (encoding == 2)
- {
- master_table_entries(ol + i).sql_statement = System.Text.Encoding.Unicode.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1) + Field_Size(2) + Field_Size(3), Field_Size(4));
- }
- else if (encoding == 3)
- {
- master_table_entries(ol + i).sql_statement = System.Text.Encoding.BigEndianUnicode.GetString(db_bytes, ent_offset + Rec_Header_Size + Field_Size(0) + Field_Size(1) + Field_Size(2) + Field_Size(3), Field_Size(4));
- }
- }
- //internal node
- }
- else if (db_bytes(Offset) == 0x5)
- {
- UInt16 Length = ConvertToInteger(Offset + 3, 2) - 1;
- UInt16 ent_offset = default(UInt16);
- for (int i = 0; i <= Length; i += 1)
- {
- ent_offset = ConvertToInteger(Offset + 12 + (i * 2), 2);
- if (Offset == 100)
- {
- ReadMasterTable((ConvertToInteger(ent_offset, 4) - 1) * page_size);
- }
- else
- {
- ReadMasterTable((ConvertToInteger(Offset + ent_offset, 4) - 1) * page_size);
- }
- }
- ReadMasterTable((ConvertToInteger(Offset + 8, 4) - 1) * page_size);
- }
- }
- private bool ReadTableFromOffset(UInt64 Offset)
- {
- //Leaf node
- if (db_bytes(Offset) == 0xd)
- {
- //Length for setting the array length for the entries
- UInt16 Length = ConvertToInteger(Offset + 3, 2) - 1;
- int ol = 0;
- if ((table_entries != null))
- {
- ol = table_entries.Length;
- Array.Resize(ref table_entries, table_entries.Length + Length + 1);
- }
- else
- {
- table_entries = new table_entry[Length + 1];
- }
- UInt64 ent_offset = default(UInt64);
- for (int i = 0; i <= Length; i += 1)
- {
- ent_offset = ConvertToInteger(Offset + 8 + (i * 2), 2);
- if (Offset != 100)
- ent_offset = ent_offset + Offset;
- //Table Cell auslesen
- dynamic t = GVL(ent_offset);
- Int64 size = CVL(ent_offset, t);
- dynamic s = GVL(ent_offset + (t - ent_offset) + 1);
- table_entries(ol + i).row_id = CVL(ent_offset + (t - ent_offset) + 1, s);
- //Table Content
- //Resetting the offset
- ent_offset = ent_offset + (s - ent_offset) + 1;
- //Now get to the Record Header
- t = GVL(ent_offset);
- s = t;
- Int64 Rec_Header_Size = CVL(ent_offset, t);
- //Record Header Length
- record_header_field[] Field_Size = null;
- Int64 size_read = (ent_offset - t) + 1;
- dynamic j = 0;
- //Now get the field sizes and fill in the Values
- while (size_read < Rec_Header_Size)
- {
- Array.Resize(ref Field_Size, j + 1);
- t = s + 1;
- s = GVL(t);
- Field_Size[j].type = CVL(t, s);
- if (Field_Size[j].type > 9)
- {
- if (IsOdd(Field_Size[j].type))
- {
- Field_Size[j].size = (Field_Size[j].type - 13) / 2;
- }
- else
- {
- Field_Size[j].size = (Field_Size[j].type - 12) / 2;
- }
- }
- else
- {
- Field_Size[j].size = SQLDataTypeSize(Field_Size[j].type);
- }
- size_read = size_read + (s - t) + 1;
- j = j + 1;
- }
- // ERROR: Not supported in C#: ReDimStatement
- int counter = 0;
- for (int k = 0; k <= Field_Size.Length - 1; k += 1)
- {
- if (Field_Size(k).type > 9)
- {
- if (!IsOdd(Field_Size(k).type))
- {
- if (encoding == 1)
- {
- table_entries(ol + i).content(k) = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + counter, Field_Size(k).size);
- }
- else if (encoding == 2)
- {
- table_entries(ol + i).content(k) = System.Text.Encoding.Unicode.GetString(db_bytes, ent_offset + Rec_Header_Size + counter, Field_Size(k).size);
- }
- else if (encoding == 3)
- {
- table_entries(ol + i).content(k) = System.Text.Encoding.BigEndianUnicode.GetString(db_bytes, ent_offset + Rec_Header_Size + counter, Field_Size(k).size);
- }
- }
- else
- {
- table_entries(ol + i).content(k) = System.Text.Encoding.Default.GetString(db_bytes, ent_offset + Rec_Header_Size + counter, Field_Size(k).size);
- }
- }
- else
- {
- table_entries(ol + i).content(k) = Convert.ToString(ConvertToInteger(ent_offset + Rec_Header_Size + counter, Field_Size(k).size));
- }
- counter = counter + Field_Size(k).size;
- }
- }
- //internal node
- }
- else if (db_bytes(Offset) == 0x5)
- {
- UInt16 Length = ConvertToInteger(Offset + 3, 2) - 1;
- UInt16 ent_offset = default(UInt16);
- for (int i = 0; i <= Length; i += 1)
- {
- ent_offset = ConvertToInteger(Offset + 12 + (i * 2), 2);
- ReadTableFromOffset((ConvertToInteger(Offset + ent_offset, 4) - 1) * page_size);
- }
- ReadTableFromOffset((ConvertToInteger(Offset + 8, 4) - 1) * page_size);
- }
- return true;
- }
- // Reads a complete table with all entries in it
- public bool ReadTable(string TableName)
- {
- // First loop through sqlite_master and look if table exists
- int found = -1;
- for (int i = 0; i <= master_table_entries.Length; i += 1) {
- if (master_table_entries[i].item_name.ToLower().CompareTo(TableName.ToLower()) == 0) {
- found = i;
- break; // TODO: might not be correct. Was : Exit For
- }
- }
- if (found == -1)
- return false;
- string fields = master_table_entries[found].sql_statement.Substring(master_table_entries[found].sql_statement.IndexOf("(") + 1).Split(",");
- for (int i = 0; i <= fields.Length - 1; i += 1) {
- fields(i) = Strings.LTrim(fields(i));
- dynamic index = fields(i).IndexOf(" ");
- if (index > 0)
- fields(i) = fields(i).Substring(0, index);
- if (fields(i).IndexOf("UNIQUE") == 0) {
- break; // TODO: might not be correct. Was : Exit For
- } else {
- Array.Resize(ref field_names, i + 1);
- field_names[i] = fields(i);
- }
- }
- return ReadTableFromOffset((master_table_entries(found).root_num - 1) * page_size);
- }
- // Returns the row count of current table
- public int GetRowCount()
- {
- return table_entries.Length;
- }
- // Returns a Value from current table in row row_num with field number field
- public string GetValue(int row_num, int field)
- {
- if (row_num >= table_entries.Length)
- return null;
- if (field >= table_entries(row_num).content.Length)
- return null;
- return table_entries(row_num).content(field);
- }
- // Returns a Value from current table in row row_num with field name field
- public string GetValue(int row_num, string field)
- {
- int found = -1;
- Second part coming
- Code
- for (int i = 0; i <= field_names.Length; i += 1)
- {
- if (field_names(i).ToLower().CompareTo(field.ToLower()) == 0)
- {
- found = i;
- break; // TODO: might not be correct. Was : Exit For
- }
- }
- if (found == -1)
- return null;
- return GetValue(row_num, found);
- }
- // Returns a String-Array with all Tablenames
- public string[] GetTableNames()
- {
- string[] retVal = null;
- dynamic arr = 0;
- for (int i = 0; i <= master_table_entries.Length - 1; i += 1)
- {
- if (master_table_entries(i).item_type == "table")
- {
- Array.Resize(ref retVal, arr + 1);
- retVal(arr) = master_table_entries(i).item_name;
- arr = arr + 1;
- }
- }
- return retVal;
- }
- // Constructor
- public SQLiteHandler(string baseName)
- {
- //Page Number n is page_size*(n-1)
- if (File.Exists(baseName))
- {
- FileSystem.FileOpen(1, baseName, OpenMode.Binary, OpenAccess.Read, OpenShare.Shared);
- string asi = Strings.Space(FileSystem.LOF(1));
- FileSystem.FileGet(1, asi);
- FileSystem.FileClose(1);
- db_bytes = System.Text.Encoding.Default.GetBytes(asi);
- if (System.Text.Encoding.Default.GetString(db_bytes, 0, 15).CompareTo("SQLite format 3") != 0)
- {
- throw new Exception("Not a valid SQLite 3 Database File");
- System.Environment.Exit(0);
- }
- if (db_bytes(52) != 0)
- {
- throw new Exception("Auto-vacuum capable database is not supported");
- System.Environment.Exit(0);
- }
- else if (ConvertToInteger(44, 4) >= 4)
- {
- throw new Exception("No supported Schema layer file-format");
- System.Environment.Exit(0);
- }
- page_size = ConvertToInteger(16, 2);
- encoding = ConvertToInteger(56, 4);
- if (encoding == 0)
- encoding = 1;
- //Now we read the sqlite_master table
- //Offset is 100 in first page
- ReadMasterTable(100);
- }
- }
- }
- }
- And as you can see there are still a few errors left over.
- So if anyone could help finish this, I would <3 you for ever - no homo[/code]
- * - XtremeDev - 02-18-2014
- Hey there, I was bored so I took some time to rewrite it. I used a VB => C# converter for some, and had to do manual coding for other stuff.
- Anyway here is the final result, I have not tested it but it does compile...
- http://pastie.org/private/6yn4zuystojovbsqsvq
- Let me know if you get any weird functionality, I can do further research if you have trouble figuring it out Tongue
- * - DarkN3ss61 - 02-18-2014
- (02-18-2014, 02:31 AM)XtremeDev Wrote: Hey there, I was bored so I took some time to rewrite it. I used a VB => C# converter for some, and had to do manual coding for other stuff.
- Anyway here is the final result, I have not tested it but it does compile...
- http://pastie.org/private/6yn4zuystojovbsqsvq
- Let me know if you get any weird functionality, I can do further research if you have trouble figuring it out Tongue
- Wow thanks so much, thanks for taking the time to do this!
- * - Banksу - 02-18-2014
- I know you're just looking for this to be converted, but I would like to propose an alternative.
- I've used MySQL, MsSQL (Linq to SQL) and more (mostly for Auxilium), and nothing I've used has come close to what I wanted.
- MongoDB is a great alternative. It is a No-SQL database, and integrates VERY easily with C#, to where all you need to do is define a class and mongodb does the rest for you.
- I might make a tutorial soon, because it's (so far) the best alternative I've found to the complicated and pain in the ass that is SQL.
- * - DarkN3ss61 - 02-18-2014
- (02-18-2014, 03:24 AM)Banksу Wrote: I know you're just looking for this to be converted, but I would like to propose an alternative.
- I've used MySQL, MsSQL (Linq to SQL) and more (mostly for Auxilium), and nothing I've used has come close to what I wanted.
- MongoDB is a great alternative. It is a No-SQL database, and integrates VERY easily with C#, to where all you need to do is define a class and mongodb does the rest for you.
- I might make a tutorial soon, because it's (so far) the best alternative I've found to the complicated and pain in the ass that is SQL.
- Thanks for this, i will defiantly look into it! :D
- * - XtremeDev - 02-18-2014
- (02-18-2014, 03:24 AM)Banksу Wrote: I know you're just looking for this to be converted, but I would like to propose an alternative.
- I've used MySQL, MsSQL (Linq to SQL) and more (mostly for Auxilium), and nothing I've used has come close to what I wanted.
- MongoDB is a great alternative. It is a No-SQL database, and integrates VERY easily with C#, to where all you need to do is define a class and mongodb does the rest for you.
- I might make a tutorial soon, because it's (so far) the best alternative I've found to the complicated and pain in the ass that is SQL.
- I would say the benefits of SQL far outweigh the costs of using it. Not only this but with No-SQL you can easily ruin your ability to scale larger if you plan on having relational tables.
- http://mongodbnosql.blogspot.com/2013/01/what-is-advantages-and-disadvantages-of.html
- Relative to "pain in the ass SQL".. have you heard of "LightSpeed" or "EntityFramework" - this sort of gets rid of the "pain in the ass" in SQL Thumbsup LightSpeed works with SQLite and many many other database types with the ease of only changing an enum value to switch backends... and has a pretty designer. Yeye
- http://www.mindscapehq.com/products/lightspeed/key-features
- its free for databases with less than 9 tables.. if you're looking for something free that supports more than 9, check into entity framework.
- http://msdn.microsoft.com/en-us/data/ef.aspx
- Not trying to start a war of NoSQL vs SQL, but from personal experiences I'd stay with SQL Superman
- * - Banksу - 02-18-2014
- (02-18-2014, 03:33 AM)XtremeDev Wrote: I would say the benefits of SQL far outweigh the costs of using it. Not only this but with No-SQL you can easily ruin your ability to scale larger if you plan on having relational tables.
- http://mongodbnosql.blogspot.com/2013/01/what-is-advantages-and-disadvantages-of.html
- Relative to "pain in the ass SQL".. have you heard of "LightSpeed" or "EntityFramework" - this sort of gets rid of the "pain in the ass" in SQL Thumbsup LightSpeed works with SQLite and many many other database types with the ease of only changing an enum value to switch backends... and has a pretty designer. Yeye
- http://www.mindscapehq.com/products/lightspeed/key-features
- its free for databases with less than 9 tables.. if you're looking for something free that supports more than 9, check into entity framework.
- http://msdn.microsoft.com/en-us/data/ef.aspx
- Not trying to start a war of NoSQL vs SQL, but from personal experiences I'd stay with SQL Superman
- What I mean by SQL being a pain in the ass, specifically with MsSQL, is that it's always been (for me anyways) extremely hit or miss as to whether or not it would install correctly the first time or not.
- Figure that in with how large the download is, how long it takes to install, etc, etc, and mongodb just seems like an easier and quicker route.
- * - XtremeDev - 02-18-2014
- (02-18-2014, 03:41 AM)Banksу Wrote: What I mean by SQL being a pain in the ass, specifically with MsSQL, is that it's always been (for me anyways) extremely hit or miss as to whether or not it would install correctly the first time or not.
- Figure that in with how large the download is, how long it takes to install, etc, etc, and mongodb just seems like an easier and quicker route.
- True.. I suppose if it was some sort of client application with a non exhaustive amount of data then it'd be just fine!
- * - DarkN3ss61 - 02-18-2014
- (02-18-2014, 03:44 AM)XtremeDev Wrote: True.. I suppose if it was some sort of client application with a non exhaustive amount of data then it'd be just fine!
- XtremeDev did you get my messages? XD because there are a few errors I am getting when i run it
- * - XtremeDev - 02-18-2014
- (02-18-2014, 03:47 AM)DarkN3ss61 Wrote: XtremeDev did you get my messages? XD because there are a few errors I am getting when i run it
- I did - unfortunately I have misplaced my skype information Glare so hold on I'll make a new account and add you!
- * - DarkN3ss61 - 02-18-2014
- (02-18-2014, 03:49 AM)XtremeDev Wrote: I did - unfortunately I have misplaced my skype information Glare so hold on I'll make a new account and add you!
- Ok cool, thanks so much for helping :D
- * - XtremeDev - 02-18-2014
- (02-18-2014, 04:17 AM)DarkN3ss61 Wrote: Ok cool, thanks so much for helping :D
- I shall accomplish this tomorrow as it is getting late. Expect a friend request sometime in the next several hours, Thanks for understanding. Pinch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement