SqliteRun.SelectRuns C# (CSharp) Méthode

SelectRuns() public static méthode

public static SelectRuns ( bool dbconOpened, int sessionID, int personID, string filterType, Orders_by order, int limit ) : string[]
dbconOpened bool
sessionID int
personID int
filterType string
order Orders_by
limit int
Résultat string[]
    public static string[] SelectRuns(bool dbconOpened, int sessionID, int personID, string filterType,
			Orders_by order, int limit)
    {
        if(!dbconOpened)
            Sqlite.Open();

        string tp = Constants.PersonTable;

        string filterSessionString = "";
        if(sessionID != -1)
            filterSessionString = " AND run.sessionID == " + sessionID;

        string filterPersonString = "";
        if(personID != -1)
            filterPersonString = " AND " + tp + ".uniqueID == " + personID;

        string filterTypeString = "";
        if(filterType != "")
            filterTypeString = " AND run.type == \"" + filterType + "\" " ;

        string orderByString = " ORDER BY upper(" + tp + ".name), run.uniqueID ";
        if(order == Orders_by.ID_DESC)
            orderByString = " ORDER BY run.uniqueID DESC ";

        string limitString = "";
        if(limit != -1)
            limitString = " LIMIT " + limit;

        dbcmd.CommandText = "SELECT " + tp + ".name, run.* " +
            " FROM " + tp + ", run " +
            " WHERE " + tp + ".uniqueID == run.personID" +
            filterSessionString +
            filterPersonString +
            filterTypeString +
            orderByString +
            limitString;

        LogB.SQL(dbcmd.CommandText.ToString());
        dbcmd.ExecuteNonQuery();

        SqliteDataReader reader;
        reader = dbcmd.ExecuteReader();

        ArrayList myArray = new ArrayList(2);

        int count = new int();
        count = 0;

        while(reader.Read()) {
            myArray.Add (reader[0].ToString() + ":" +	//person.name
                    reader[1].ToString() + ":" +	//run.uniqueID
                    reader[2].ToString() + ":" + 	//run.personID
                    reader[3].ToString() + ":" + 	//run.sessionID
                    reader[4].ToString() + ":" + 	//run.type
                    Util.ChangeDecimalSeparator(reader[5].ToString()) + ":" + //run.distance
                    Util.ChangeDecimalSeparator(reader[6].ToString()) + ":" + //run.time
                    reader[7].ToString() + ":" + 	//description
                    reader[8].ToString() + ":" +	//simulated
                    Util.IntToBool(Convert.ToInt32(reader[9])) //initialSpeed
                    );
            count ++;
        }

        reader.Close();

        if(!dbconOpened)
            Sqlite.Close();

        string [] myRuns = new string[count];
        count =0;
        foreach (string line in myArray) {
            myRuns [count++] = line;
        }

        return myRuns;
    }

Usage Example

    public PrepareEventGraphRunSimple(double time, double speed, int sessionID, int personID, string table, string type)
    {
        Sqlite.Open();

        //obtain data
        runsAtSQL = SqliteRun.SelectRuns(true, sessionID, personID, type,
                                         Sqlite.Orders_by.ID_DESC, 10); //select only last 10


        string sqlSelect = "distance/time";

        personMAXAtSQLAllSessions = SqliteSession.SelectMAXEventsOfAType(true, -1, personID, table, type, sqlSelect);
        personMAXAtSQL            = SqliteSession.SelectMAXEventsOfAType(true, sessionID, personID, table, type, sqlSelect);
        sessionMAXAtSQL           = SqliteSession.SelectMAXEventsOfAType(true, sessionID, -1, table, type, sqlSelect);

        //distancePersonAVGAtSQL = SqliteSession.SelectAVGEventsOfAType(true, sessionID, personID, table, type, "distance");
        //distanceSessionAVGAtSQL = SqliteSession.SelectAVGEventsOfAType(true, sessionID, -1, table, type, "distance");
        //better to know speed like:
        //SELECT AVG(distance/time) from run; than
        //SELECT AVG(distance) / SELECT AVG(time)
        //first is ok, because is the speed AVG
        //2nd is not good because it tries to do an AVG of all distances and times
        personAVGAtSQL  = SqliteSession.SelectAVGEventsOfAType(true, sessionID, personID, table, type, sqlSelect);
        sessionAVGAtSQL = SqliteSession.SelectAVGEventsOfAType(true, sessionID, -1, table, type, sqlSelect);

        this.time  = time;
        this.speed = speed;

        Sqlite.Close();
    }
All Usage Examples Of SqliteRun::SelectRuns