Example #1
0
    void Start()
    {
        // Gather a list of weapons and their type names pulled from the weapontype table
        SimpleSQL.SimpleDataTable dt = dbManager.QueryGeneric(
            "SELECT " +
            "W.WeaponID, " +
            "W.WeaponName, " +
            "W.Damage, " +
            "W.Cost, " +
            "W.Weight, " +
            "W.WeaponTypeID, " +
            "T.Description AS WeaponTypeDescription " +
            "FROM " +
            "Weapon W " +
            "JOIN WeaponType T " +
            "ON W.WeaponTypeID = T.WeaponTypeID " +
            "ORDER BY " +
            "W.WeaponID "
            );

        // output the list of weapons
        // note that we can reference the field/column by number (the order in the SELECT list, starting with zero) or by name
        outputText.text = "Weapons\n\n";
        int rowIndex = 0;

        foreach (SimpleSQL.SimpleDataRow dr in dt.rows)
        {
            outputText.text += "<color=#1abc9c>Name:</color> '" + dr[1].ToString() + "' " +
                               "<color=#1abc9c>Damage:</color>" + dr["Damage"].ToString() + " " +
                               "<color=#1abc9c>Cost:</color>" + dr[3].ToString() + " " +
                               "<color=#1abc9c>Weight:</color>" + dr["Weight"].ToString() + " " +
                               "<color=#1abc9c>Type:</color>" + dr[6] + "\n";

            rowIndex++;
        }


        // get the weapon record that has a WeaponID > 4 with a single statement
        // warning, this will fail if no record exists, so we use a try catch block
        outputText.text += "\nFirst record where the WeaponID > 4: ";
        try
        {
            outputText.text += dbManager.QueryGeneric("SELECT WeaponName FROM Weapon WHERE WeaponID > 4").rows[0][0].ToString() + "\n";
        }
        catch
        {
            outputText.text += "No record found\n";
        }
    }