Related to:
http://drupal.org/node/1176002
When trying to run a migration it tries to save starttime field with a float (1321958004087.1) into a bigint field. MySQL let's you do this (truncates the decimal) but Postgres fails. I've seen this is a common problem with the drupal database abstraction layer.
Error:
An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /batch?id=7&op=do StatusText: Service unavailable (with message) ResponseText: PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "1321958004087.1" LINE 1: ...initialHighwater) VALUES ('CatalogKlubNode', '1', '132195800... ^: INSERT INTO si.migrate_log (machine_name, process_type, starttime, initialHighwater) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( ) in MigrationBase->beginProcess() (line 738 of /var/www/petrol/repo/d7/branches/theme.multilanguage/webdir/sites/all/modules/migrate/includes/base.inc).PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "1321958004087.1" LINE 1: ...initialHighwater) VALUES ('CatalogKlubNode', '1', '132195800... ^: INSERT INTO si.migrate_log (machine_name, process_type, starttime, initialHighwater) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( ) in MigrationBase->beginProcess() (line 738 of /var/www/petrol/repo/d7/branches/theme.multilanguage/webdir/sites/all/modules/migrate/includes/base.inc). ( ! ) Fatal error: Exception thrown without a stack frame in Unknown on line 0 Call Stack #TimeMemoryFunctionLocation 10.857828331964_drupal_exception_handler( )../bootstrap.inc:0 20.858628333800_drupal_log_error( )../bootstrap.inc:2158
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | postgres_error_trying-1349246-9.patch | 620 bytes | mikeryan |
Comments
Comment #1
Putr commentedFound a fix:
base.inc line 764
base.inc line 730
Seeing how you're operating with really large numbers i dont think you need the decimal point anyway.
Comment #2
mikeryanCommitted, thanks!
For future reference, please read http://drupal.org/patch/submit on how to submit patches.
Comment #4
TheMentat commentedI get the following error:
PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR:[error]
invalid input syntax for integer: "1.34426532893E+12"
LINE 1: ...time, initialHighwater) VALUES ('Candidate', '1', '1.3442653...
^: INSERT INTO
migrate_log (machine_name, process_type, starttime, initialHighwater) VALUES
(:db_insert_placeholder_0, :db_insert_placeholder_1,
:db_insert_placeholder_2, :db_insert_placeholder_3); Array
Would sprintf() be the best way to solve this problem?
Comment #4.0
TheMentat commentedGrammar
Comment #5
sebcorbin commentedThis is still active for me (PHP 5.4, PostGres 9.4). Comment #4 fixes it
Comment #6
mikeryanI think casting to int is cleaner than sprintf. @SebCorbin, does the attached patch work for you?
Comment #7
sebcorbin commentedSorry it doesn't as the integer is bigger than PHP_INT, thus overflowing and giving a negative integer
Comment #8
mikeryanComment #9
mikeryan%d didn't work, nor any other integer type specifier (all truncate to a 32-bit integer), but %s seems to work for me. @SebCorbin, can you try the attached patch with Postgres?
Thanks.
Comment #10
sebcorbin commentedWe actually used
sprintf('%u', round(microtime(TRUE) * 1000))because somehow the query was trying to insert1.1234567+e19Comment #11
mikeryan%u does not work for me on MySQL, PHP 5.5.23 on Mac OS X - while the existing code, or the %s, produces correct timestamps like 1438383410969, using %u produces the likes of 3864369549.
Does %s work for you?
Comment #12
sebcorbin commentedUnfortunately, no:
Comment #13
sebcorbin commentedWith php 5.5.24:
A friend of mine has PHP 5.4.41 (32bits):
This said, we should not use any of these functions, we should rely on the database, but Mysql doesn't support sub-second timestamps.
Comment #14
mikeryanResetting to "Needs work" - we do not yet have a solution that works across different PHP versions and database engines.