Exemplo n.º 1
0
check_table_blacklisted($G_CONTROLLER_DBLINK, $G_TABLE_DETAILS['id'], $G_TOKEN_PRIVILEGE_DATA['id']);
# Handling our global json parsing
$_JPOST = PostParser::decode();
# Setting up our return content
$content = new stdClass();
$content->success = true;
$content->env = PostParser::create_attribute($G_APP_ENVIRONMENT);
$content->ids = [];
$content->insert_ids = [];
$content->rejected = [];
# We will have some duplicate ids to return
if (UPDATE_DUPLICATES) {
    $content->update_ids = [];
}
# Checking for whitelisting
$whitelist = NQ_WHITELIST_COLUMNS ? get_whitelist_columns($G_CONTROLLER_DBLINK, $G_APP_DATA['id'], $G_TABLE_DETAILS['id'], $G_TOKEN_PRIVILEGE_DATA['id']) : [];
# Getting the table id bitmask
if (!isset($G_PARTITION_BITSIZE[$G_TABLE_DETAILS['partition_size']])) {
    exit_fail(NQ_INVALID_VALUE, LANG_TABLE_INVALID_PARTITION_SIZE);
}
$bitmask = $G_PARTITION_BITSIZE[$G_TABLE_DETAILS['partition_size']];
# Tracking
$inserted_count = 0;
$write_rows = 0;
$partitions = [];
$partitions_affected = new stdClass();
# Turning into an array
$_JPOST = is_array($_JPOST) ? $_JPOST : [$_JPOST];
# Can't be too large
if (count($_JPOST) > NQ_MAX_INSERT_ROW_COUNT) {
    exit_fail(NQ_INVALID_VALUE, LANG_TO_MANY_INSERT_ROWS);
Exemplo n.º 2
0
$partition_query = "\t\tSELECT\n\t\t\t\t\t\t`p`.*,\n\t\t\t\t\t\t`d`.`host`,\n\t\t\t\t\t\t`d`.`username`,\n\t\t\t\t\t\t`d`.`password`,\n\t\t\t\t\t\t`d`.`database`\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . NQ_TABLE_PARTITIONS_TABLE . " `p`\n\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\t" . NQ_SERVERS_TABLE . " `d`\n\t\t\t\t\t\tON\n\t\t\t\t\t\t\t`d`.`id`=`p`.`host_id`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`table_id`=" . (int) $G_TABLE_DETAILS['id'] . "\n\t\t\t\t\t\t" . $evaluation_query . "\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\t" . (isset($_CGET['partitionorder']) && $_CGET['partitionorder'] == 'value' ? "`evaluation`" : "`number`") . "\n\t\t\t\t\t\t" . (isset($_CGET['partitionordersort']) && $_CGET['partitionordersort'] == 'DESC' ? "DESC" : "ASC") . "";
$partition_results = mysqli_multi_result_query($G_CONTROLLER_DBLINK, $partition_query);
# Processing each partition
$query = false;
$partitions_affected = new stdClass();
while ($partition_data = mysqli_fetch_assoc($partition_results)) {
    # Connecting to our dblinks
    $partition_dblink = mysqli_shared_connect($partition_data['host'], $partition_data['username'], $partition_data['password'], $G_SHARED_DBLINKS);
    $partitions_affected->{$partition_data['id']} = (object) ['data' => $partition_data, 'dblink' => $partition_dblink, 'database' => $partition_data['database']];
    # First partition, new query object
    if ($query === false) {
        # Creating our new parser
        $query = new MySQLParser($partition_dblink, $partition_data['table_name'], $partition_data['database']);
        # Checking for whitelisting
        if (NQ_WHITELIST_COLUMNS) {
            $whitelist = get_whitelist_columns($G_CONTROLLER_DBLINK, $G_APP_DATA['id'], $G_TABLE_DETAILS['id'], $G_TOKEN_PRIVILEGE_DATA['id']);
            if (NQ_WHITELIST_EXISTENTIAL ? count($whitelist) > 0 : true) {
                $query->whitelist_columns($whitelist);
            }
        }
        # Blacklisting the locked and partitioned fields
        $query->blacklist_columns(explode(',', NQ_LOCKED_FIELDS));
        $query->blacklist_columns(explode(',', $partition_data['partition_column']));
        # Order by
        if (isset($_CGET['order'])) {
            $order_sort = isset($_CGET['ordersort']) ? explode(',', $_CGET['ordersort']) : [];
            $query->add_order_by(explode(',', $_CGET['order']), $order_sort);
        }
        # Adding our update columns
        $query->add_update_columns(PostParser::decode());
        # Where columns
Exemplo n.º 3
0
 $unset_link_id = false;
 $evaluation_query = count($partition_evaluations) != 0 ? " AND `evaluation` IN ('" . implode("','", $partition_evaluations) . "')" : "";
 $partition_query = "\tSELECT\n\t\t\t\t\t\t\t\t`p`.*,\n\t\t\t\t\t\t\t\t`d`.`host`,\n\t\t\t\t\t\t\t\t`d`.`username`,\n\t\t\t\t\t\t\t\t`d`.`password`,\n\t\t\t\t\t\t\t\t`d`.`database`\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t" . NQ_TABLE_PARTITIONS_TABLE . " `p`\n\t\t\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\t\t\t" . NQ_SERVERS_TABLE . " `d`\n\t\t\t\t\t\t\t\tON\n\t\t\t\t\t\t\t\t\t`d`.`id`=`p`.`host_id`\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t`table_id`=" . (int) $table_settings['id'] . "\n\t\t\t\t\t\t\t\t" . $evaluation_query . "\n\t\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t\t`evaluation` ASC";
 $partition_results = mysqli_multi_result_query($G_CONTROLLER_DBLINK, $partition_query);
 while ($partition_data = mysqli_fetch_assoc($partition_results)) {
     # Connecting to the correct database
     $dblink = mysqli_shared_connect($partition_data['host'], $partition_data['username'], $partition_data['password'], $G_SHARED_DBLINKS);
     # Adding our tracking
     $G_READ_PARTITION_IDS[] = $partition_data['id'];
     # We need to create a new query
     if ($query == false) {
         # Creating our new parser
         $query = new MySQLParser($dblink, $partition_data['table_name'], $partition_data['database']);
         # Checking for whitelisting
         if (NQ_WHITELIST_COLUMNS) {
             $whitelist = get_whitelist_columns($G_CONTROLLER_DBLINK, $G_APP_DATA['id'], $table_settings['id'], $G_TOKEN_DATA['id']);
             if (NQ_WHITELIST_EXISTENTIAL ? count($whitelist) > 0 : true) {
                 $query->whitelist_columns($whitelist);
             }
         }
         # Excluding from the table
         $query->blacklist_columns($G_COLUMNS_EXCLUDED);
         # Adding our select columns
         $select_columns = $G_COLUMNS_SELECTED;
         if ($select_columns != '*' && !in_array($attached['column'], $select_columns)) {
             $select_columns[] = $attached['column'];
             $unset_link_id = true;
         }
         $query->add_select_columns($select_columns, false, $table_settings['alias'], true);
         # Where columns
         $query->add_where_columns([$attached['column'] => '[]' . implode(',', $column_values)], false, $table_settings['alias']);