samedi 3 janvier 2015

SQLite file is empty

So... I'm working on project that requires small but quick access to database file. And now i can create file, but i'm not able to fill it. I'm calling queries that should create table, but file is still empty. Could please someone help me?



static class Database
{
private static SQLiteConnection _connection;
public static bool Connected {
get { return _connection != null; }
}

public static void Connect(string file)
{
_connection = new SQLiteConnection("Data Source=" + file + ";Version=3;");
_connection.Open();
}

public static void Disconnect()
{
_connection.Close();
_connection = null;
}

public static SQLiteDataReader Query(string sql)
{
SQLiteCommand cmd = new SQLiteCommand(sql, _connection);
return cmd.ExecuteReader();
}

public static void ExecuteFile(string file)
{
foreach (string line in File.ReadLines(file).Where(line => !line.Trim().StartsWith("--")))
{
Query(line.Trim());
}
}

public static void Install(string file)
{
SQLiteConnection.CreateFile(file);
Connect(file);

// Installation
ExecuteFile("install.sql");

Disconnect();
}
}


I'm calling 'Install' method to create that database. And here is that install file:



-- Database configuration
PRAGMA journal_mode = OFF
PRAGMA foreign_keys = ON

-- Database schema creation
CREATE TABLE Metadata(ID INTEGER PRIMARY KEY AUTOINCREMENT,name VARCHAR(256), value VARCHAR(256))
CREATE TABLE T1 (ID VARCHAR(64) PRIMARY KEY NOT NULL, name VARCHAR(256), parent VARCHAR(64) REFERENCES T1(ID))
CREATE TABLE T2(ID VARCHAR(64) PRIMARY KEY NOT NULL, msg TEXT, userName VARCHAR(256), userEMail VARCHAR(256), userNick VARCHAR(256), t1 VARCHAR(256) REFERENCES T1(ID), position INTEGER)
CREATE TABLE ChangeRecords(ID INTEGER PRIMARY KEY AUTOINCREMENT, changeAction INTEGER, filePath TEXT, data BLOB, position INTEGER, lenght INTEGER, t2 VARCHAR(64) REFERENCES T2(ID))
CREATE TABLE T3(ID INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(256), url TEXT)

-- Metadata defaults
INSERT INTO Metadata (name,value) VALUES ('credentials_name','null')
INSERT INTO Metadata (name,value) VALUES ('credentials_email','null')
INSERT INTO Metadata (name,value) VALUES ('credentials_nickname','null')
INSERT INTO Metadata (name,value) VALUES ('prefer_nickname','false')
INSERT INTO Metadata (name,value) VALUES ('root','master')
INSERT INTO Branches (id, name) VALUES ('fc613b4dfd6736a7bd268c8a0e74ed0d1c04a959f59dd74ef2874983fd443fc9','master')


After all this file is still empty (0bytes)!


Aucun commentaire:

Enregistrer un commentaire