Example #1
0
    //used on Sqlite main convertPersonAndPersonSessionTo77()
    public ArrayList SelectAllPersonSessionsOfAPerson(int personID)
    {
        dbcmd.CommandText = "SELECT * FROM " + Constants.PersonSessionOldWeightTable + " WHERE personID == " + personID + " ORDER BY uniqueID";
        LogB.SQL(dbcmd.CommandText.ToString());
        SqliteDataReader reader;

        reader = dbcmd.ExecuteReader();

        ArrayList myArray = new ArrayList(1);

        while (reader.Read())
        {
            PersonSessionOld ps = new PersonSessionOld(
                Convert.ToInt32(reader[0].ToString()),                              //uniqueID
                Convert.ToInt32(reader[1].ToString()),                              //personID
                Convert.ToInt32(reader[2].ToString()),                              //sessionID
                Convert.ToDouble(Util.ChangeDecimalSeparator(reader[3].ToString())) //weight
                );
            myArray.Add(ps);
        }
        reader.Close();
        return(myArray);
    }
Example #2
0
    //used on Sqlite main convertPersonAndPersonSessionTo77()
    public ArrayList SelectAllPersonSessionsOfAPerson(int personID)
    {
        dbcmd.CommandText = "SELECT * FROM " + Constants.PersonSessionOldWeightTable + " WHERE personID == " + personID + " ORDER BY uniqueID";
        LogB.SQL(dbcmd.CommandText.ToString());
        SqliteDataReader reader;
        reader = dbcmd.ExecuteReader();

        ArrayList myArray = new ArrayList(1);
        while(reader.Read()) {
            PersonSessionOld ps = new PersonSessionOld(
                    Convert.ToInt32(reader[0].ToString()), //uniqueID
                    Convert.ToInt32(reader[1].ToString()), //personID
                    Convert.ToInt32(reader[2].ToString()), //sessionID
                    Convert.ToDouble(Util.ChangeDecimalSeparator(reader[3].ToString())) //weight
                    );
            myArray.Add(ps);
        }
        reader.Close();
        return myArray;
    }
Example #3
0
    /*
     * The problem of this method is that uses class constructors: person, jump, ...
     * and if the sqlite version is updated from a really old version
     * maybe the object has to be converted from really older class to old, and then to new class (two conversions)
     * and this can have problems in the class construction
     * The best seem to have a boolean that indicates if certain conversion has done before
     * (see bool runAndRunIntervalInitialSpeedAdded)
     */
    protected internal static void convertTables(Sqlite sqliteObject, string tableName, int columnsBefore, ArrayList columnsToAdd, bool putDescriptionInMiddle)
    {
        conversionSubRate = 1;
        conversionSubRateTotal = -1; //unknown yet

        //2st create convert temp table
        sqliteObject.createTable(Constants.ConvertTempTable);

        //2nd copy all data from desired table to temp table (in event tables, adding the simulated column)
        ArrayList myArray = new ArrayList(2);
        dbcmd.CommandText = "SELECT * " +
            "FROM " + tableName + " ORDER BY uniqueID";
        LogB.SQL(dbcmd.CommandText.ToString());
        SqliteDataReader reader;
        reader = dbcmd.ExecuteReader();

        while(reader.Read()) {
            string [] myReaderStr = new String[columnsBefore + columnsToAdd.Count];
            int i;
            for (i=0; i < columnsBefore; i ++)
                myReaderStr[i] = reader[i].ToString();

            foreach (string myStr in columnsToAdd)
                myReaderStr[i++] = myStr;

            if (putDescriptionInMiddle) {
                //string [] strFull = changePos.Split(new char[] {':'});
                //int row1 = Convert.ToInt32(strFull[0]);
                //int row2 = Convert.ToInt32(strFull[1]);
                string desc = myReaderStr[6];
                myReaderStr[6] = myReaderStr[7];
                myReaderStr[7] = myReaderStr[8];
                myReaderStr[8] = myReaderStr[9];
                myReaderStr[9] = desc;
            }

            if(tableName == Constants.PersonOldTable) {
                PersonOld myPerson =  new PersonOld(myReaderStr);
                myArray.Add(myPerson);
            } else if(tableName == Constants.SessionTable) {
                Session mySession = new Session(myReaderStr);
                myArray.Add(mySession);
            } else if(tableName == Constants.RunIntervalTypeTable) {
                RunType myType = new RunType(myReaderStr, true); //interval
                myArray.Add(myType);
            } else if(tableName == Constants.PersonSessionOldWeightTable) {
                PersonSessionOld myPS = new PersonSessionOld(myReaderStr);
                myArray.Add(myPS);
            } else {
                Event myEvent =  new Event();
                switch (tableName) {
                    case Constants.JumpTable:
                        myEvent = new Jump(myReaderStr);
                        break;
                    case Constants.JumpRjTable:
                        myEvent = new JumpRj(myReaderStr);
                        break;
                    case Constants.RunTable:
                        myEvent = new Run(myReaderStr);
                        break;
                    case Constants.RunIntervalTable:
                        myEvent = new RunInterval(myReaderStr);
                        break;
                    case Constants.ReactionTimeTable:
                        myEvent = new ReactionTime(myReaderStr);
                        break;
                    case Constants.PulseTable:
                        myEvent = new Pulse(myReaderStr);
                        break;
                }
                myArray.Add(myEvent);
            }
        }
        reader.Close();

        LogB.SQL("1" + tableName);

        conversionSubRateTotal = myArray.Count * 2;

        if(tableName == Constants.PersonOldTable) {
            foreach (PersonOld myPerson in myArray) {
                myPerson.InsertAtDB(true, Constants.ConvertTempTable);
                conversionSubRate ++;
            }
        } else if(tableName == Constants.SessionTable) {
            foreach (Session mySession in myArray) {
                mySession.InsertAtDB(true, Constants.ConvertTempTable);
                conversionSubRate ++;
            }
        } else if(tableName == Constants.RunIntervalTypeTable) {
            foreach (RunType type in myArray) {
                type.InsertAtDB(true, Constants.ConvertTempTable, true); //last true is for interval
                conversionSubRate ++;
            }
        } else if(tableName == Constants.PersonSessionOldWeightTable) {
            foreach (PersonSessionOld ps in myArray) {
                ps.InsertAtDB(true, Constants.ConvertTempTable);
                conversionSubRate ++;
            }
        } else {
            foreach (Event myEvent in myArray) {
                myEvent.InsertAtDB(true, Constants.ConvertTempTable);
                conversionSubRate ++;
            }
        }

        LogB.SQL("2" + tableName);
        //3rd drop desired table
        Sqlite.dropTable(tableName);

        LogB.SQL("3" + tableName);
        //4d create desired table (now with new columns)
        sqliteObject.createTable(tableName);

        LogB.SQL("4" + tableName);

        //5th insert data in desired table
        if(tableName == Constants.PersonOldTable) {
            foreach (PersonOld myPerson in myArray) {
                myPerson.InsertAtDB(true, tableName);
                conversionSubRate ++;
            }
        } else if(tableName == Constants.SessionTable) {
            foreach (Session mySession in myArray) {
                mySession.InsertAtDB(true, tableName);
                conversionSubRate ++;
            }
        } else if(tableName == Constants.RunIntervalTypeTable) {
            foreach (RunType type in myArray) {
                type.InsertAtDB(true, tableName, true); //last true is for interval
                conversionSubRate ++;
            }
        } else if(tableName == Constants.PersonSessionOldWeightTable) {
            foreach (PersonSessionOld ps in myArray) {
                ps.InsertAtDB(true, tableName);
                conversionSubRate ++;
            }
        } else {
            foreach (Event myEvent in myArray) {
                myEvent.InsertAtDB(true, tableName);
                conversionSubRate ++;
            }
        }

        LogB.SQL("5" + tableName);
        //6th drop temp table
        Sqlite.dropTable(Constants.ConvertTempTable);
    }