public void Initialise(string connectionString)
        {
            m_connectionString = connectionString;

            m_log.Info("[ESTATE DB]: Sqlite - connecting: "+m_connectionString);

            m_connection = new SqliteConnection(m_connectionString);
            m_connection.Open();

            Assembly assem = GetType().Assembly;
            Migration m = new Migration(m_connection, assem, "EstateStore");
            m.Update();

            m_connection.Close();
            m_connection.Open();

            Type t = typeof(EstateSettings);
            m_Fields = t.GetFields(BindingFlags.NonPublic |
                                   BindingFlags.Instance |
                                   BindingFlags.DeclaredOnly);

            foreach (FieldInfo f in m_Fields)
                if (f.Name.Substring(0, 2) == "m_")
                    m_FieldMap[f.Name.Substring(2)] = f;
        }
Esempio n. 2
0
    // Use this for initialization
    void Start()
    {

        //E:\Etude\Projet\Projet_4e_semestre\GITHUB\New_Unity_Project\Assets


        const string connectionString = "URI=file:E://Etude/Projet/Projet_4e_semestre/GITHUB/New_Unity_Project/Assets/testbdd.s3db";
        IDbConnection dbcon = new SqliteConnection(connectionString);
        IDbCommand dbcmd = dbcon.CreateCommand();
        try
        {
            dbcon.Open();

            const string sql = "select nomcarte from carte";
            dbcmd.CommandText = sql;
            IDataReader reader = dbcmd.ExecuteReader();
            while (reader.Read())
            {
                string NomCarte = reader.GetString(0);
                Debug.Log("Carte: " + NomCarte + "\n");
            }
            reader.Dispose();

        }
        catch (Exception ex)
        {
            Debug.Log(ex.Message);
        }
        dbcmd.Dispose();
        dbcon.Close();

    }
Esempio n. 3
0
    public Store(string fname, string cachedir)
    {
        updates = new ArrayList ();
        newchans = new ArrayList ();
        connection = new SqliteConnection ("URI=file:" + fname);
        connection.Open ();

        IDbCommand dbcmd = connection.CreateCommand ();
        // setting encoding only works on sqlite3
        //dbcmd.CommandText = "PRAGMA encoding = \"UTF-8\";";
        //if (dbcmd.ExecuteNonQuery () != 0) {
        //	throw new Exception ("Couldn't set encoding");
        //}
        string sql = "PRAGMA table_info(channel)";
        dbcmd = connection.CreateCommand ();
        dbcmd.CommandText = sql;
        try {
            IDataReader result = dbcmd.ExecuteReader ();
         			if (!result.Read ()) {
         				// schema doesn't exist.
         				System.Console.WriteLine ("Creating new database schema");
         				CreateSchema ();
            }
            result.Close ();
        } catch (Exception e) {
            // TODO: catch further exceptions here.
            System.Console.WriteLine ("Error executing reader: {0}", e.ToString ());
        }
        _cachedir = cachedir;
        InitializeCache ();
        // TODO: catch problems making the cache dir
    }
Esempio n. 4
0
 public SqliteStore(string connectionString, string table)
     : base(table)
 {
     this.connectionString = connectionString;
     dbcon = new SqliteConnection(connectionString);
     dbcon.Open();
 }
Esempio n. 5
0
        /// <summary>
        /// Creates a new connection to the icontent.cache file.
        /// </summary>
        /// <param name="filename">The file to connect to.</param>
        public IGADatabaseConnector(String filename)
        {
            try {
                sqlite = new SqliteConnection("URI=file:" + filename + ",version=3");
                sqlite.Open();

                SqliteCommand query = new SqliteCommand("SELECT [appId] FROM [contentlist] LIMIT 1", sqlite);
                Object result = query.ExecuteScalar();
                sqlite.Close();
                if (result == null)
                {
                    this._appID = 0;
                }
                else
                {
                    this._appID = (int)result;
                }

                if (this._appID > 0) {
                    this._appSupported = Common.AppInfos.ContainsKey(this._appID);
                } else {
                    this._appSupported = false;
                }

                if (this._appSupported)
                {
                    _appInfo = Common.AppInfos[this._appID];
                }

            } catch (Exception) {
                throw new DatabaseConnectionFailureException();
            }
        }
Esempio n. 6
0
    // Use this for initialization
    void Start () {
        const string connectionString = "URI=file:E://Etude/Projet/Projet_4e_semestre/GITHUB/New_Unity_Project/Assets/testbdd.s3db";
        IDbConnection dbcon = new SqliteConnection(connectionString);
        IDbCommand dbcmd = dbcon.CreateCommand();
        try
        {
            dbcon.Open();

            const string sql = "SELECT DISTINCT nomcarte, puisscrea, vitcrea, typecrea, pvcrea, nomatk, dommatk, vitatk FROM carte INNER JOIN creature ON creature.IDCARTE = carte.IDCARTE INNER JOIN j_crea_atk On j_crea_atk.IDCREA = creature.IDCARTE INNER JOIN atk On atk.IDATK = j_crea_atk.IDATK WHERE carte.IDCARTE = '1' AND atk.IDATK='1'";
            dbcmd.CommandText = sql;
            IDataReader reader = dbcmd.ExecuteReader();
            while (reader.Read())
            {
                IDCARTE = reader.GetInt32(0);
            }
            reader.Dispose();

        }
        catch (Exception ex)
        {
            Debug.Log(ex.Message);
        }
        dbcmd.Dispose();
        dbcon.Close();
    }
Esempio n. 7
0
        public SQLiteGenericData(string connectionString)
        {
            m_Connection = new SqliteConnection(connectionString);
            m_Connection.Open();

            Migration m = new Migration(m_Connection, this.GetType().Assembly, "GenericStore");
            m.Update();
        }
Esempio n. 8
0
    public void init(int idcarte, string numserie, int idatk, int idatk2)
    {
        this.idcarte = idcarte;
        this.numserie = numserie;

        xdeck = this.transform.position.x;
        ydeck = this.transform.position.y;
        zdeck = this.transform.position.z;
        ObservJ1 = false;
        ObservJ2 = false;

        mettredsdeck = false;

        const string connectionString = "URI=file:E://Etude/Projet/Projet_4e_semestre/GITHUB/New_Unity_Project/Assets/testbdd.s3db";

        IDbConnection dbcon = new SqliteConnection(connectionString);
        IDbCommand dbcmd = dbcon.CreateCommand();
        try
        {
            dbcon.Open();

            string sql = "SELECT DISTINCT nomcarte, puisscrea, vitcrea, typecrea, pvcrea, nomatk, dommatk, vitatk FROM carte INNER JOIN creature ON creature.IDCARTE = carte.IDCARTE INNER JOIN j_crea_atk On j_crea_atk.IDCREA = creature.IDCARTE INNER JOIN atk On atk.IDATK = j_crea_atk.IDATK WHERE carte.NUMSERIE = '" + this.numserie + "' AND atk.IDATK=" + this.idatk + "";

            dbcmd.CommandText = sql;
            IDataReader reader = dbcmd.ExecuteReader();
            while (reader.Read())
            {
                NomCarte = reader.GetString(0);
                puisscrea = reader.GetInt32(1);
                vitcrea = reader.GetInt32(2);
                typecrea = reader.GetString(3);
                pvcrea = reader.GetInt32(4);
                nomatk = reader.GetString(5);
                dommatk = reader.GetInt32(6);
                vitatk = reader.GetInt32(7);
            }
            reader.Dispose();

            string sql2 = "SELECT DISTINCT nomcarte, puisscrea, vitcrea, typecrea, pvcrea, nomatk, dommatk, vitatk FROM carte INNER JOIN creature ON creature.IDCARTE = carte.IDCARTE INNER JOIN j_crea_atk On j_crea_atk.IDCREA = creature.IDCARTE INNER JOIN atk On atk.IDATK = j_crea_atk.IDATK WHERE carte.NUMSERIE = '" + this.numserie + "' AND atk.IDATK=" + this.idatk2 + "";
            dbcmd.CommandText = sql2;

            IDataReader reader2 = dbcmd.ExecuteReader();
            while (reader2.Read())
            {
                nomatk2 = reader2.GetString(5);
                dommatk2 = reader2.GetInt32(6);
                vitatk2 = reader2.GetInt32(7);
            }
            reader2.Dispose();
        }
        catch (Exception ex)
        {
            Debug.Log(ex.Message);
        }
        dbcmd.Dispose();
        dbcon.Close();

    }
 public virtual SqliteConnection getNewConnection()
 {
     SqliteConnectionStringBuilder conStringBuilder = new SqliteConnectionStringBuilder();
     conStringBuilder.Uri = config.DatabaseUri;
     conStringBuilder.Version = config.DatabaseVersion;
     SqliteConnection con = new SqliteConnection(conStringBuilder.ConnectionString);
     con.Open ();
     return con;
 }
Esempio n. 10
0
 public static IDataReader ExecuteSQL(string db, string sql)
 {
     var connection = new SqliteConnection(db);
     connection.Open();
     var command = connection.CreateCommand();
     command.CommandText = sql;
     var result = command.ExecuteReader();
     connection.Close();
     return result;
 }
Esempio n. 11
0
 public SqliteDataKit()
 {
     conn = new SqliteConnection ();
     if (!File.Exists (Path.Combine (Configuration.GetInstance ().UserConfigDir, dbfile)))
     isNew = true;
     conn.ConnectionString = "URI=file:" + Path.Combine (Configuration.GetInstance ().UserConfigDir, dbfile);
     conn.Open ();
     if (isNew)
     SetupDb ();
 }
 public new void ExecuteNonQuery(string sql, string connectionString)
 {
     using (SqliteConnection conn = new SqliteConnection(connectionString))
     {
         SqliteCommand cmd = new SqliteCommand(sql, conn);
         cmd.CommandTimeout = 1200;
         conn.Open();
         cmd.ExecuteNonQuery();
         conn.Close();
     }
 }
 public new object ExecuteScalar(string sql, string connectionString)
 {
     using (SqliteConnection conn = new SqliteConnection(connectionString))
     {
         SqliteCommand cmd = new SqliteCommand(sql, conn);
         cmd.CommandTimeout = 1200;
         conn.Open();
         object retVal = cmd.ExecuteScalar();
         conn.Close();
         return retVal;
     }
 }
Esempio n. 14
0
        public bool Convert()
        {
            try
            {
                SqliteConnection conn = new SqliteConnection(m_connectionString);
                conn.Open();

                Assembly assem = GetType().Assembly;
                Migration m = new Migration(conn, assem, "RegionStore");

                int version = m.Version;

                if (version <= 14)
                {
                    if (version == 0)
                    {
                        //read rex tables and add to rex database
                        m_log.Info("[regionstore] converting rex tables to rexobjectproperties");
                        if (!ConvertLegacyRexDataToModreX())
                        {
                            conn.Close();
                            return false;
                        }

                        m_log.Info("[RegionStore] Update region migrations");
                        //Add new field to Land table
                        SqliteCommand addAuthbyerIDCmd = new SqliteCommand(addAuthbyerID, conn);
                        addAuthbyerIDCmd.ExecuteNonQuery();

                        //Change migration to version 1
                        m.Version = 1;
                    }

                    //Run migrations up to 9
                    //Note: this run migrations only to point nine since only those files exist in application resources.
                    m.Update();

                    //Skip over 10. Change version to 10
                    //This skips adding of the ClickAction since that already exists in 0.4 database
                    //m.Version = 10;
                }

                conn.Close();
                return true;
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[RegionStore] Migration failed. Reason: {0}", e);
                return false;
            }
        }
Esempio n. 15
0
    public Database(string file)
    {
        bool create = false;
        if (!File.Exists (file)) {
            create = true;
        }

        try {
            StreamReader srVersion = new StreamReader (file+".version");
            dbVersion = srVersion.ReadToEnd ();
            if (dbVersion != null) {
                dbVersion = dbVersion.Trim();
            }
            srVersion.Close();
        }
        catch {
            dbVersion = null;
        }

        string connectionString = "URI=file:"+file;
        connection = new SqliteConnection(connectionString);
        connection.Open();
        command = connection.CreateCommand();

        if (create) {
            Conf.EmptyCache();
            Assembly thisAssembly = Assembly.GetEntryAssembly ();
            Stream stream = thisAssembly.GetManifestResourceStream("Database.sql");
            if (stream != null) {
                StreamReader sr = new StreamReader (stream);
                string sql = sr.ReadToEnd();
                command.CommandText = sql;
                command.ExecuteNonQuery();

                StreamWriter swVersion = new StreamWriter (file+".version", false);
                swVersion.Write (Defines.VERSION);
                swVersion.Close();

                dbVersion = Defines.VERSION;
            }
            else {
                System.Console.WriteLine("Error creating the database");
            }
        }

        if (dbVersion == null || !dbVersion.Equals (Defines.VERSION)) {
            UpdateDatabase(file, dbVersion);
        }
    }
Esempio n. 16
0
        /// <summary>
        /// <list type="bullet">
        /// <item>Initialises AssetData interface</item>
        /// <item>Loads and initialises a new SQLite connection and maintains it.</item>
        /// <item>use default URI if connect string is empty.</item>
        /// </list>
        /// </summary>
        /// <param name="dbconnect">connect string</param>
        override public void Initialise(string dbconnect)
        {
            if (dbconnect == string.Empty)
            {
                dbconnect = "URI=file:Asset.db,version=3";
            }
            m_conn = new SqliteConnection(dbconnect);
            m_conn.Open();

            Assembly assem = GetType().Assembly;
            Migration m = new Migration(m_conn, assem, "AssetStore");
            m.Update();

            return;
        }
Esempio n. 17
0
    //Diese Methode Schreibt ein Gegebenes Auto in die Datenbank.
    // Das Auto wird als Parameter gegeben
    public void addauto(Autos autodaten)
    {
        IDbConnection _connection = new SqliteConnection(_strDBName);
        IDbCommand _command = _connection .CreateCommand();
        string sql;

        _connection .Open();

        sql = "INSERT INTO AUTOS (KENNZEICHEN, STATUS) Values ('"+ autodaten.getKennzeichen ()+"','"+autodaten.getStatus ()+"')";
        _command.CommandText = sql;
        _command.ExecuteNonQuery();

        _command.Dispose();
        _command = null;
        _connection .Close();
        _connection.Dispose ();
        _connection = null;
        //Debug.Log (autodaten.getKennzeichen ());
    }
Esempio n. 18
0
    // Hier wird eine gegebene Drone in die Tabelle DRONEN eingefüllt
    public void addDrone(Drone drone)
    {
        IDbConnection _connection = new SqliteConnection(_strDBName);
        IDbCommand _command = _connection .CreateCommand();
        string sql;

        _connection .Open();

        sql = "INSERT INTO DRONEN (DRONENNAME,AKTUELLERKNOTEN,HOMEPUNKTID, STATUS,CARTOSHOW) Values ('"+ drone.getName()+"','2','2','0','ef')";
        _command.CommandText = sql;
        _command.ExecuteNonQuery();

        _command.Dispose();
        _command = null;
        _connection .Close();
        _connection.Dispose ();
        _connection = null;
        sql = null;
    }
Esempio n. 19
0
        public bool Convert()
        {
            try
            {
                SqliteConnection conn = new SqliteConnection(m_connectionString);
                conn.Open();

                Assembly assem = GetType().Assembly;
                Migration m = new Migration(conn, assem, "InventoryStore");
                if (m.Version == 0)
                {
                    //Apply all changes to db
                    SqliteCommand addSalePriceCmd = new SqliteCommand(addSalePrice, conn);
                    addSalePriceCmd.ExecuteNonQuery();

                    SqliteCommand addSaleTypeCmd = new SqliteCommand(addSaleType, conn);
                    addSaleTypeCmd.ExecuteNonQuery();

                    SqliteCommand addCreationDateCmd = new SqliteCommand(addCreationDate, conn);
                    addCreationDateCmd.ExecuteNonQuery();

                    SqliteCommand addGroupIDCmd = new SqliteCommand(addGroupID, conn);
                    addGroupIDCmd.ExecuteNonQuery();

                    SqliteCommand addGroupOwnedCmd = new SqliteCommand(addGroupOwned, conn);
                    addGroupOwnedCmd.ExecuteNonQuery();

                    SqliteCommand addFlagsCmd = new SqliteCommand(addFlags, conn);
                    addFlagsCmd.ExecuteNonQuery();

                    //then change version number
                    m.Version = 1;
                }
                return true;
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[InventoryStore] Migration failed. Reason: {0}", e);
                return false;
            }
        }
        /// <summary>
        /// <list type="bullet">
        /// <item>Initialises Inventory interface</item>
        /// <item>Loads and initialises a new SQLite connection and maintains it.</item>
        /// <item>use default URI if connect string string is empty.</item>
        /// </list>
        /// </summary>
        /// <param name="dbconnect">connect string</param>
        public void Initialise(string dbconnect)
        {
            if (!m_Initialized)
            {
                m_Initialized = true;

                if (dbconnect == string.Empty)
                {
                    dbconnect = "URI=file:inventoryStore.db,version=3";
                }
                m_log.Info("[INVENTORY DB]: Sqlite - connecting: " + dbconnect);
                conn = new SqliteConnection(dbconnect);

                conn.Open();

                Assembly assem = GetType().Assembly;
                Migration m = new Migration(conn, assem, "InventoryStore");
                m.Update();

                SqliteCommand itemsSelectCmd = new SqliteCommand(invItemsSelect, conn);
                invItemsDa = new SqliteDataAdapter(itemsSelectCmd);
                //            SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa);

                SqliteCommand foldersSelectCmd = new SqliteCommand(invFoldersSelect, conn);
                invFoldersDa = new SqliteDataAdapter(foldersSelectCmd);

                ds = new DataSet();

                ds.Tables.Add(createInventoryFoldersTable());
                invFoldersDa.Fill(ds.Tables["inventoryfolders"]);
                setupFoldersCommands(invFoldersDa, conn);
                m_log.Info("[INVENTORY DB]: Populated Inventory Folders Definitions");

                ds.Tables.Add(createInventoryItemsTable());
                invItemsDa.Fill(ds.Tables["inventoryitems"]);
                setupItemsCommands(invItemsDa, conn);
                m_log.Info("[INVENTORY DB]: Populated Inventory Items Definitions");

                ds.AcceptChanges();
            }
        }
Esempio n. 21
0
    public ArrayList Select(string quer)
    {
        Resultd = new ArrayList();
        string connectionString = "URI=file:" + Application.dataPath + "/Qjournaldb.s3db";
        IDbConnection dbcon = new SqliteConnection(connectionString);
        dbcon.Open();
        IDbCommand dbcmd = dbcon.CreateCommand();
        dbcmd.CommandText = quer;
        IDataReader reader = dbcmd.ExecuteReader();
        while (reader.Read())
        {
            Resultd.Add(reader.GetString(2));
            //Debug.Log(reader.GetString(2));
        }

        // clean up
        reader.Dispose();
        dbcmd.Dispose();
        dbcon.Close();
        return Resultd;
    }
Esempio n. 22
0
 // Hier wird überprüft ob eine bestimmte Tabelle in der Datenbank existieren. Die Anzahl der Funde wird Zurückgegeben. 1=Existiert; 0=Gibt es nicht
 public int abfrageexisttabelle(string Tabellenname)
 {
     IDbConnection _connection = new SqliteConnection(_strDBName);
     IDbCommand _command = _connection .CreateCommand();
     string sql;
     IDataReader _reader;
     _connection .Open();
     sql = "SELECT count(name) as Count FROM sqlite_master WHERE type='table' AND name='"+Tabellenname+"'";
     _command.CommandText = sql;
     _reader = _command.ExecuteReader();
     _reader.Read ();
     _connection .Close();
     _connection.Dispose ();
     _connection = null;
     _command.Dispose ();
     _command = null;
     int anzahl = System.Convert.ToInt32 (_reader ["Count"]);
     _reader.Close();
     _reader.Dispose ();
     _reader = null;
     return anzahl;
 }
        public SQLiteAuthenticationData(string connectionString, string realm)
                : base(connectionString)
        {
            m_Realm = realm;
            m_connectionString = connectionString;

            if (!m_initialized)
            {
                m_Connection = new SqliteConnection(connectionString);
                m_Connection.Open();

                using (SqliteConnection dbcon = (SqliteConnection)((ICloneable)m_Connection).Clone())
                {
                    dbcon.Open();
                    Migration m = new Migration(dbcon, GetType().Assembly, "AuthStore");
                    m.Update();
                    dbcon.Close();
                }

                m_initialized = true;
            }
        }
Esempio n. 24
0
        public bool Convert()
        {
            try
            {
                SqliteConnection conn = new SqliteConnection(m_connectionString);
                conn.Open();

                Assembly assem = GetType().Assembly;
                Migration m = new Migration(conn, assem, "UserStore");

                if (m.Version == 0)
                {
                    m.Version = 1;
                }

                conn.Close();
                return true;
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[UserStore] Migration failed. Reason: {0}", e);
                return false;
            }
        }
Esempio n. 25
0
        /// <summary>
        /// <list type="bullet">
        /// <item>Initialises User Interface</item>
        /// <item>Loads and initialises a new SQLite connection and maintains it.</item>
        /// <item>use default URI if connect string string is empty.</item>
        /// </list>
        /// </summary>
        /// <param name="connect">connect string</param>
        override public void Initialise(string connect)
        {
            // default to something sensible
            if (connect == "")
                connect = "URI=file:userprofiles.db,version=3";

            SqliteConnection conn = new SqliteConnection(connect);

            // This sucks, but It doesn't seem to work with the dataset Syncing :P
            g_conn = conn;
            g_conn.Open();

            Assembly assem = GetType().Assembly;
            Migration m = new Migration(g_conn, assem, "UserStore");
            m.Update();


            ds = new DataSet();
            da = new SqliteDataAdapter(new SqliteCommand(userSelect, conn));
            dua = new SqliteDataAdapter(new SqliteCommand(userAgentSelect, conn));
            daf = new SqliteDataAdapter(new SqliteCommand(userFriendsSelect, conn));
            daa = new SqliteDataAdapter(new SqliteCommand(AvatarAppearanceSelect, conn));
            //if (daa == null) m_log.Info("[SQLiteUserData]: daa = null");

            lock (ds)
            {
                ds.Tables.Add(createUsersTable());
                ds.Tables.Add(createUserAgentsTable());
                ds.Tables.Add(createUserFriendsTable());
                ds.Tables.Add(createAvatarAppearanceTable());

                setupUserCommands(da, conn);
                da.Fill(ds.Tables["users"]);

                setupAgentCommands(dua, conn);
                dua.Fill(ds.Tables["useragents"]);

                setupUserFriendsCommands(daf, conn);
                daf.Fill(ds.Tables["userfriends"]);

                setupAvatarAppearanceCommands(daa, conn);
                daa.Fill(ds.Tables["avatarappearance"]);
            }

            return;
        }
Esempio n. 26
0
		static void Main(string[] args)
		{
			Console.WriteLine("If this test works, you should get:");
			Console.WriteLine("Data 1: 5");
			Console.WriteLine("Data 2: Mono");

			Console.WriteLine("create SqliteConnection...");
			SqliteConnection dbcon = new SqliteConnection();
			
			// the connection string is a URL that points
			// to a file.  If the file does not exist, a 
			// file is created.

			// "URI=file:some/path"
			string connectionString =
				"URI=file:SqliteTest.db";
			Console.WriteLine("setting ConnectionString using: " + 
				connectionString);
			dbcon.ConnectionString = connectionString;
				
			Console.WriteLine("open the connection...");
			dbcon.Open();

			Console.WriteLine("create SqliteCommand to CREATE TABLE MONO_TEST");
			SqliteCommand dbcmd = new SqliteCommand();
			dbcmd.Connection = dbcon;
			
			dbcmd.CommandText = 
				"CREATE TABLE MONO_TEST ( " +
				"NID INT, " +
				"NDESC TEXT )";
			Console.WriteLine("execute command...");
			dbcmd.ExecuteNonQuery();

			Console.WriteLine("set and execute command to INSERT INTO MONO_TEST");
			dbcmd.CommandText =
				"INSERT INTO MONO_TEST  " +
				"(NID, NDESC )"+
				"VALUES(5,'Mono')";
			dbcmd.ExecuteNonQuery();

			Console.WriteLine("set command to SELECT FROM MONO_TEST");
			dbcmd.CommandText =
				"SELECT * FROM MONO_TEST";
			SqliteDataReader reader;
			Console.WriteLine("execute reader...");
			reader = dbcmd.ExecuteReader();

			Console.WriteLine("read and display data...");
			while(reader.Read()) {
				Console.WriteLine("Data 1: " + reader[0].ToString());
				Console.WriteLine("Data 2: " + reader[1].ToString());
			}

			Console.WriteLine("read and display data using DataAdapter...");
			SqliteDataAdapter adapter = new SqliteDataAdapter("SELECT * FROM MONO_TEST", connectionString);
			DataSet dataset = new DataSet();
			adapter.Fill(dataset);
			foreach(DataTable myTable in dataset.Tables){
				foreach(DataRow myRow in myTable.Rows){
					foreach (DataColumn myColumn in myTable.Columns){
						Console.WriteLine(myRow[myColumn]);
					}
				}
			}

			
			Console.WriteLine("clean up...");
			dataset.Dispose();
			adapter.Dispose();
			reader.Close();
			dbcmd.Dispose();
			dbcon.Close();

			Console.WriteLine("Done.");
		}
 private DataTable ExecuteDataTable(string sql)
 {
     using (SqliteConnection conn = new SqliteConnection(connectionString))
     {
         sql = sql + " --dataProfilerIgnore";
         SqliteCommand cmd = new SqliteCommand(sql, conn);
         cmd.CommandTimeout = 1200;
         conn.Open();
         SqliteDataAdapter da = new SqliteDataAdapter(cmd);
         DataSet ds = new DataSet();
         da.Fill(ds);
         return ds.Tables[0];
     }
 }
        public virtual void PostInitialise()
        {
            if (!enabled)
                return;

            if (Util.IsWindows())
                Util.LoadArchSpecificWindowsDll("sqlite3.dll");

            //IConfig startupConfig = config.Configs["Startup"];

            dbConn = new SqliteConnection("URI=file:LocalUserStatistics.db,version=3");
            dbConn.Open();
            CreateTables(dbConn);

            Prototype_distributor protodep = new Prototype_distributor();
            Updater_distributor updatedep = new Updater_distributor();
            ActiveConnectionsAJAX ajConnections = new ActiveConnectionsAJAX();
            SimStatsAJAX ajSimStats = new SimStatsAJAX();
            LogLinesAJAX ajLogLines = new LogLinesAJAX();
            Default_Report defaultReport = new Default_Report();
            Clients_report clientReport = new Clients_report();
            Sessions_Report sessionsReport = new Sessions_Report();

            reports.Add("prototype.js", protodep);
            reports.Add("updater.js", updatedep);
            reports.Add("activeconnectionsajax.html", ajConnections);
            reports.Add("simstatsajax.html", ajSimStats);
            reports.Add("activelogajax.html", ajLogLines);
            reports.Add("default.report", defaultReport);
            reports.Add("clients.report", clientReport);
            reports.Add("sessions.report", sessionsReport);

            reports.Add("sim.css", new Prototype_distributor("sim.css"));
            reports.Add("sim.html", new Prototype_distributor("sim.html"));
            reports.Add("jquery.js", new Prototype_distributor("jquery.js"));

            ////
            // Add Your own Reports here (Do Not Modify Lines here Devs!)
            ////

            ////
            // End Own reports section
            ////

            MainServer.Instance.AddHTTPHandler("/SStats/", HandleStatsRequest);
            MainServer.Instance.AddHTTPHandler("/CAPS/VS/", HandleUnknownCAPSRequest);
        }
        public void Initialise(string connectionString)
        {
            m_connectionString = connectionString;
            m_log.InfoFormat("[UserLogModule]: Sqlite - connecting: {0}", m_connectionString);

            try
            {
                if (Util.IsWindows())
                    Util.LoadArchSpecificWindowsDll("sqlite3.dll");

                m_connection = new SqliteConnection(m_connectionString);
                m_connection.Open();

                Migration m = new Migration(m_connection, Assembly, "sqlite");
                m.Update();
            }
            catch (Exception ex)
            {
                m_log.ErrorFormat("[UserLogModule]: Initial sqlite exception for URI '{0}', Exception: {1}", m_connectionString, ex.Message);
                Environment.Exit(-1);
            }
        }
Esempio n. 30
0
		static void Test(bool v3, string encoding) {
			if (!v3)
				Console.WriteLine("Testing Version 2" + (encoding != null ? " with " + encoding + " encoding" : ""));
			else
				Console.WriteLine("Testing Version 3");
				
			System.IO.File.Delete("SqliteTest.db");
		
			SqliteConnection dbcon = new SqliteConnection();
			
			// the connection string is a URL that points
			// to a file.  If the file does not exist, a 
			// file is created.

			// "URI=file:some/path"
			string connectionString =
				"URI=file:SqliteTest.db";
			if (v3)
				connectionString += ",Version=3";
			if (encoding != null)
				connectionString += ",encoding=" + encoding;
			dbcon.ConnectionString = connectionString;
				
			dbcon.Open();

			SqliteCommand dbcmd = new SqliteCommand();
			dbcmd.Connection = dbcon;
			
			dbcmd.CommandText = 
				"CREATE TABLE MONO_TEST ( " +
				"NID INT, " +
				"NDESC TEXT, " +
				"NTIME DATETIME); " +
				"INSERT INTO MONO_TEST  " +
				"(NID, NDESC, NTIME) " +
				"VALUES(1,'One (unicode test: \u05D0)', '2006-01-01')";
			Console.WriteLine("Create & insert modified rows = 1: " + dbcmd.ExecuteNonQuery());

			dbcmd.CommandText =
				"INSERT INTO MONO_TEST  " +
				"(NID, NDESC, NTIME) " +
				"VALUES(:NID,:NDESC,:NTIME)";
			dbcmd.Parameters.Add( new SqliteParameter("NID", 2) );
			dbcmd.Parameters.Add( new SqliteParameter(":NDESC", "Two (unicode test: \u05D1)") );
			dbcmd.Parameters.Add( new SqliteParameter(":NTIME", DateTime.Now) );
			Console.WriteLine("Insert modified rows with parameters = 1, 2: " + dbcmd.ExecuteNonQuery() + " , " + dbcmd.LastInsertRowID());

			dbcmd.CommandText =
				"INSERT INTO MONO_TEST  " +
				"(NID, NDESC, NTIME) " +
				"VALUES(3,'Three, quoted parameter test, and next is null; :NTIME', NULL)";
			Console.WriteLine("Insert with null modified rows and ID = 1, 3: " + dbcmd.ExecuteNonQuery() + " , " + dbcmd.LastInsertRowID());

			dbcmd.CommandText =
				"INSERT INTO MONO_TEST  " +
				"(NID, NDESC, NTIME) " +
				"VALUES(4,'Four with ANSI char: ü', NULL)";
			Console.WriteLine("Insert with ANSI char ü = 1, 4: " + dbcmd.ExecuteNonQuery() + " , " + dbcmd.LastInsertRowID());

			dbcmd.CommandText =
				"INSERT INTO MONO_TEST  " +
				"(NID, NDESC, NTIME) " +
				"VALUES(?,?,?)";
			dbcmd.Parameters.Clear();
			IDbDataParameter param1 = dbcmd.CreateParameter();
			param1.DbType = DbType.DateTime;
			param1.Value = 5;
			dbcmd.Parameters.Add(param1);			
			IDbDataParameter param2 = dbcmd.CreateParameter();
			param2.Value = "Using unnamed parameters";
			dbcmd.Parameters.Add(param2);
			IDbDataParameter param3 = dbcmd.CreateParameter();
			param3.DbType = DbType.DateTime;
			param3.Value = DateTime.Parse("2006-05-11 11:45:00");
			dbcmd.Parameters.Add(param3);
			Console.WriteLine("Insert with unnamed parameters = 1, 5: " + dbcmd.ExecuteNonQuery() + " , " + dbcmd.LastInsertRowID());

			dbcmd.CommandText =
				"SELECT * FROM MONO_TEST";
			SqliteDataReader reader;
			reader = dbcmd.ExecuteReader();

			Console.WriteLine("read and display data...");
			while(reader.Read())
				for (int i = 0; i < reader.FieldCount; i++)
					Console.WriteLine(" Col {0}: {1} (type: {2}, data type: {3})",
						i, reader[i] == null ? "(null)" : reader[i].ToString(), reader[i] == null ? "(null)" : reader[i].GetType().FullName, reader.GetDataTypeName(i));

			dbcmd.CommandText = "SELECT NDESC FROM MONO_TEST WHERE NID=2";
			Console.WriteLine("read and display a scalar = 'Two': " + dbcmd.ExecuteScalar());

			dbcmd.CommandText = "SELECT count(*) FROM MONO_TEST";
			Console.WriteLine("read and display a non-column scalar = 3: " + dbcmd.ExecuteScalar());

			Console.WriteLine("read and display data using DataAdapter/DataSet...");
			SqliteDataAdapter adapter = new SqliteDataAdapter("SELECT * FROM MONO_TEST", connectionString);
			DataSet dataset = new DataSet();
			adapter.Fill(dataset);
			foreach(DataTable myTable in dataset.Tables){
				foreach(DataRow myRow in myTable.Rows){
					foreach (DataColumn myColumn in myTable.Columns){
						Console.WriteLine(" " + myRow[myColumn]);
					}
				}
			}

			/*Console.WriteLine("read and display data using DataAdapter/DataTable...");
			DataTable dt = new DataTable();
			adapter.Fill(dt);
			DataView dv = new DataView(dt);
			foreach (DataRowView myRow in dv) {
				foreach (DataColumn myColumn in myRow.Row.Table.Columns) {
					Console.WriteLine(" " + myRow[myColumn.ColumnName]);
				}
			}*/
       		       		            
			try {
				dbcmd.CommandText = "SELECT NDESC INVALID SYNTAX FROM MONO_TEST WHERE NID=2";
				dbcmd.ExecuteNonQuery();
				Console.WriteLine("Should not reach here.");
			} catch (Exception e) {
				Console.WriteLine("Testing a syntax error: " + e.GetType().Name + ": " + e.Message);
			}

			/*try {
				dbcmd.CommandText = "SELECT 0/0 FROM MONO_TEST WHERE NID=2";
				Console.WriteLine("Should not reach here: " + dbcmd.ExecuteScalar());
			} catch (Exception e) {
				Console.WriteLine("Testing an execution error: " + e.GetType().Name + ": " + e.Message);
			}*/

			dataset.Dispose();
			adapter.Dispose();
			reader.Close();
			dbcmd.Dispose();
			dbcon.Close();
		}