示例#1
0
文件: db.php 项目: surfrock66/torque
function quote_names($column_names)
{
    $quoted_names = array();
    foreach ($column_names as $name) {
        $quoted_names[] = quote_name($name);
    }
    return implode(", ", $quoted_names);
}
示例#2
0
// Grab the session number
if (isset($_GET["id"]) and in_array($_GET["id"], $sids)) {
    $session_id = mysql_real_escape_string($_GET['id']);
    // Get the torque key->val mappings
    $keyquery = mysql_query("SELECT id,description,units FROM {$db_name}.{$db_keys_table};") or die(mysql_error());
    $keyarr = [];
    while ($row = mysql_fetch_assoc($keyquery)) {
        $keyarr[$row['id']] = array($row['description'], $row['units']);
    }
    // 2015.08.04 - edit by surfrock66 - Adding experimental support for unlimited vars,
    //   while requiring no default PID
    $selectstring = "time";
    $i = 1;
    while (isset($_GET["s{$i}"])) {
        ${'v' . $i} = $_GET["s{$i}"];
        $selectstring = $selectstring . "," . quote_name(${'v' . $i});
        $i = $i + 1;
    }
    // Get data for session
    $sessionqry = mysql_query("SELECT {$selectstring} FROM {$db_table} WHERE session=" . quote_value($session_id) . " ORDER BY time DESC;") or die(mysql_error());
    while ($row = mysql_fetch_assoc($sessionqry)) {
        $i = 1;
        while (isset(${'v' . $i})) {
            if (substri_count($keyarr[${'v' . $i}][0], "Speed") > 0) {
                $x = intval($row[${'v' . $i}]) * $speed_factor;
                ${'v' . $i . '_measurand'} = $speed_measurand;
            } elseif (substri_count($keyarr[${'v' . $i}][0], "Temp") > 0) {
                $x = $temp_func(floatval($row[${'v' . $i}]));
                ${'v' . $i . '_measurand'} = $temp_measurand;
            } else {
                $x = intval($row[${'v' . $i}]);
示例#3
0
                     $submitval = 1;
                 } else {
                     $submitval = 0;
                 }
             }
         }
     }
     // If the field doesn't already exist, add it to the database
     if (!in_array($key, $dbfields) and $submitval == 1) {
         if (is_float($value)) {
             // Add field if it's a float
             $sqlalter = "ALTER TABLE {$db_table} ADD " . quote_name($key) . " float NOT NULL default '0'";
             $sqlalterkey = "INSERT INTO {$db_keys_table} (id, description, type, populated) VALUES (" . quote_value($key) . ", " . quote_value($key) . ", 'float', '1')";
         } else {
             // Add field if it's a string, specifically varchar(255)
             $sqlalter = "ALTER TABLE {$db_table} ADD " . quote_name($key) . " VARCHAR(255) NOT NULL default 'Not Specified'";
             $sqlalterkey = "INSERT INTO {$db_keys_table} (id, description, type, populated) VALUES (" . quote_value($key) . ", " . quote_value($key) . ", 'varchar(255)', '1')";
         }
         mysql_query($sqlalter, $con) or die(mysql_error());
         mysql_query($sqlalterkey, $con) or die(mysql_error());
     }
 }
 // The way session uploads work, there's a separate HTTP call for each datapoint.  This is why raw logs is
 //  so huge, and has so much repeating data. This is my attempt to flatten the redundant data into the
 //  sessions table; this code checks if there is already a row for the current session, and if there is, only
 //  update the ending time and the count of datapoints.  If there isn't a row, insert one.
 $rawkeys = array_merge($keys, $sesskeys, $sessprofilekeys);
 $rawvalues = array_merge($values, $sessvalues, $sessprofilevalues);
 if (sizeof($rawkeys) === sizeof($rawvalues) && sizeof($rawkeys) > 0 && sizeof($sesskeys) === sizeof($sessvalues) && sizeof($sesskeys) > 0) {
     // Now insert the data for all the fields into the raw logs table
     $sql = "INSERT INTO {$db_table} (" . quote_names($rawkeys) . ") VALUES (" . quote_values($rawvalues) . ")";
示例#4
0
        //from the fieldname:id we need to get id
        $split_data = explode(':', $field_id);
        $id = $split_data[1];
        $field_name = $split_data[0];
        echo "\nField Name: '{$field_name}'\nField ID: '{$id}'\nValue: '{$val}'\n";
        if (!empty($id) && !empty($field_name) && !empty($val)) {
            if ($field_name == 'populated') {
                if ($val == 'true') {
                    $val = 1;
                } else {
                    $val = 0;
                }
            }
            //update the values
            $query = "UPDATE {$db_name}.{$db_keys_table} SET " . quote_name($field_name) . " = " . quote_value($val) . " WHERE id = " . quote_value($id);
            echo "\n{$query}\n";
            mysql_query($query) || die(mysql_error());
            if ($field_name == 'type') {
                $query = "ALTER TABLE {$db_name}.{$db_table} MODIFY " . quote_name($id) . " " . mysql_real_escape_string($val) . " NOT NULL DEFAULT '0'";
                echo $query;
                mysql_query($query) || die(mysql_error());
            }
            echo "Updated";
        } else {
            echo "Invalid Requests 1";
        }
    }
} else {
    echo "Invalid Requests 2";
}
mysql_close($con);