Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught InvalidArgumentException: The number of values (1) does not match the field count (13). #4

Closed
cborchmann opened this issue Apr 30, 2019 · 7 comments

Comments

@cborchmann
Copy link

Hallo,
first, thank you for this cool piece of software. It woks well for me when filling the $inserter->queue() manually, but i get this error when using data from a variable $inserter->queue($values).
My $values contains 7,'DDWWWB',NULL,'SWR',51.26,12.35,36975,-64,42,406,'2019-04-29','2019-04-29 10:17:01.900',1556525821.9

Any hint for me?

@BenMorel
Copy link
Member

Hi, are you passing an array of values? queue() expects the values directly:

$inserter->queue(7, 'DDWWWB', NULL, ...);

and not:

$inserter->queue([7, 'DDWWWB', NULL, ...]);

@cborchmann
Copy link
Author

cborchmann commented Apr 30, 2019

Hi, my var_dump echos this:

string(117) "7,'4B1616',NULL,'SWR1310',51.764226,12.048035,36975,-64,42,406,'2019-04-29','2019-04-29 10:17:01.900000',1556525821.9"

The manual version is:

$inserter->queue(7,'4B1616',NULL,'SWR1310',51.764226,12.048035,36975,-64,42,406,'2019-04-29','2019-04-29 10:17:01.900000',1556525821.9); which works fine...

@BenMorel
Copy link
Member

In the first case you're passing the arguments as a string, which is obviously a single argument.
Where is your data coming from?

@cborchmann
Copy link
Author

Hi, i´m prasing an JSON String.

@BenMorel
Copy link
Member

BenMorel commented May 1, 2019

Please share the code!

@cborchmann
Copy link
Author

Hello Ben,

my approach to build a $ values variable was not necessary at all. I realized that I can simply feed the values into the function.

Here is my working code example:

$inserter = new BulkInserter($pdo, 'flights_tmp', ['source', 'hex', 'squawk', 'callsign', 'altitude']);

  foreach ($row_outer[$x] as $row) {
            
        // hex: the 24-bit ICAO identifier of the aircraft, as 6 hex digits.
        // The identifier may start with '~', this means that the address is a non-ICAO address (e.g. from TIS-B).
        if(isset($row['hex'])) {
            $hex = strtoupper(trim($row['hex']));
        }else $hex = NULL;

        // squawk: the 4-digit squawk (octal representation)
        if(isset($row['squawk'])) {
            $squawk = intval($row['squawk']);
        }else $squawk = NULL;

        // flight: the flight name / callsign
        if(isset($row['flight'])) {
            $flight = strtoupper(trim($row['flight']));
        }else $flight = '?';

        // lat, lon: the aircraft position in decimal degrees
        if(isset($row['lat'])) {
            $latitude = floatval($row['lat']);
        }else $latitude = NULL;

        // lat, lon: the aircraft position in decimal degrees
        if(isset($row['lon'])) {
            $longitude = floatval($row['lon']);
        }else $longitude = NULL;

          $inserter->queue($source, $hex, $squawk, $squawk, $flight, $altitude);

      }

      $inserter->flush();

@BenMorel
Copy link
Member

BenMorel commented May 2, 2019

Hi, exactly. If you're passing an array, it's considered a single argument hence the argument count does not match. Alternatively, you can unpack an array this way:

$values = [$source, $hex, $squawk, $squawk, $flight, $altitude];

$inserter->queue(...$values); // unpacking the array into multiple arguments

@BenMorel BenMorel closed this as completed May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants