createTable() protected method

protected createTable ( ) : void
return void
コード例 #1
0
ファイル: main.cs プロジェクト: GNOME/chronojump
    /*
     * 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);
    }
コード例 #2
0
ファイル: main.cs プロジェクト: GNOME/chronojump
    /*
     * useful to do a conversion from an int to a double
     * used on jump.angle
     * we done on sqlite/jump.cs:
     * on createTable change "angle INT" to "angle FLOAT"
     * then call this alterTableColumn
     *
     * but CAUTION: doing this, all the float data is converted to .0
     * eg: 27.35 will be 27.0
     *     -1 will be -1.0
     *
     * if we don't use this, and we have created a column as int, and introduce floats or doubles,
     * we can insert ok the float or doubles, but on select we will have ints
     */
    protected internal static void alterTableColumn(Sqlite sqliteObject, string tableName, int columns)
    {
        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 adding the simulated column
        ArrayList myArray = new ArrayList(2);
        dbcmd.CommandText = "SELECT * " +
            "FROM " + tableName + " ORDER BY uniqueID";
        SqliteDataReader reader;
        reader = dbcmd.ExecuteReader();
        LogB.SQL(dbcmd.CommandText.ToString());

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

            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();

        conversionSubRateTotal = myArray.Count * 2;

        foreach (Event myEvent in myArray) {
            myEvent.InsertAtDB(true, Constants.ConvertTempTable);
            conversionSubRate ++;
        }

        //3rd drop desired table
        Sqlite.dropTable(tableName);

        //4d create desired table (now with new columns)
        sqliteObject.createTable(tableName);

        //5th insert data in desired table
        foreach (Event myEvent in myArray) {
            myEvent.InsertAtDB(true, tableName);
            conversionSubRate ++;
        }

        //6th drop temp table
        Sqlite.dropTable(Constants.ConvertTempTable);
    }