MySQL export/import empty/null multilinestring - mysql

Using phpMyadmin
I have exported a database which has a table with a spatial multilinestring field. Some of the records in this table have a null entry in this field.
When trying to import, the table fails the import with this message.
1416 - Cannot get geometry object from data you send to the GEOMETRY field
What do I need to replace the null value with for records where this field is not required?

I finally worked this out so posting back in case anyone else struggles with this.
It was not to do with null entries as I first thought. In phpMyAdmin, the insert scripts batch the inserts together. if you select the option 'include column names in every INSERT statement', each record will have it's own insert statement.
Then when you import, it will show you which record is failing. It was not failing on a null entry.
I then ran a query on the failing record like this to view the points in the multilinestring
SELECT ST_ASTEXT(Polylines) FROM myTable WHERE id = 100
This showed me that there was only 1 point in one of the Polylines. This was the issue. Importing a polyline with only 1 point into MySQL fails - which makes sense (but it did allow the record to be inserted in the first place). In my case, I set the single point polylines to null to fix this issue.
I was exporting and importing from the same versions of mySQL : 5.7.26

Related

Sync SQL Binary column to MySQL table

I’m attempting to use a piece of software (Layer2 Cloud Connector) to sync a local SQL table (Sage software) to a remote MySQL database where the data is used reports generated via the company's web app. We are doing this with about 12 tables, and have been doing so for almost two years without any issues.
Background:
I’m using a simple piece of software the uses a SELECT statement to sync records from one table to another using ODBC. In this case from SQL (SQLTable) to MySQL (MySQLTable). To do so, the software requires a SELECT statement for each table, a PK field, and, being ODBC-based, a provider. For SQL I'm using the Actian Zen 4.5, and for MySQL I'm using the MySQL ODBC 5.3.
Here is a screenshot of what the setup screen looks like for each of the tables. I have omitted the other column names that I'm syncing to make the SELECT statement more readable. The other columns are primarily varchar or int types.
Problem
For unrelated reasons, we must now sync a new table. Like most of the other tables, it has a primary key column named rGUID of type binary. When initially setting up the other tables, I tried to sync the primary key as a binary type to a MySQL binary column, but it failed when attempting to verify the SELECT statement on the SQLServer side with the error “Cannot remove this column, because it is a part of the constraint Constraint1 on the table SQLTable”.
Example of what I see for the the GUID/rGUID primary key values stored in the SQLTable via Access, or in MySQL after syncing as string:
¡狻➽䪏蚯㰛蓪
Ҝ諺䖷ᦶ肸邅
ब惈蠷䯧몰吲론�
ॺ䀙㚪䄔麽骧⸍薉
To get around this, I use CAST in the SQLTable SELECT statement to CAST the binary value as a string using: CAST(GUID as nchar(8)) as GUID, and then set up the MySQL column as a VARCHAR(32) using utf8_general_ci collation.
This has worked great for every other table since we originally set this up. But this additional table has considerably more records (about 120,000 versus 5,000-10,000), and though I’m able to sync 10,000 – 15,000 successfully, when I try to sync the entire table I get about 10-12 errors such as:
The metabase record 'd36d2dbe-fa89-4712-be4c-6b212367004b' is marked
to be added. The table 'SQLTable' does not contain a corresponding
row. Changes made to this metabase record will be reset to the
initial state.
I don't understand what is causing the above error or how to work past it.
What I’ve tried so far:
I’ve confirmed the SQLTable has no other unique fields that could be
used as PK in place of the rGUID column
I’ve tried use different type, length and collation settings on the
MySQL table, and have had mixed success, but ultimately still get
errors when attempting to sync the entire table.
I’ve also tried tweaking the CAST settings for the SQL SELECT
statement, but nchar(8) seems to work best for the other tables
I've tried syncing using HASHBYTES('SHA1', GUID) as GUID and syncing
the value of that, but get the below ODBC error
I was thinking perhaps I could convert the SQL GUID to its value, then sync that as a varchar (or a binary), but my attempts at using CONVERT in the SQLTable SELECT statement have failed
Settings I used for all the other tables:
SQL SELECT Statement: SELECT CAST(GUID as nchar(8)) as GUID, OtherColumns FROM SQLTable;
MYSQL SELECT Statement: SELECT GUID, OtherColumns FROM MySQLTable;
Primary Key Field: GUID
Primary Key Field Type: String
MySQL Column Type/Collation: VARCHAR(32), utf8_general_ci
Any help or suggestions at all would be great. I've been troubleshooting this in my spare time for a couple of weeks now, and have no had much success. I'm not particularly familiar with the binary type, and am hoping someone might have an idea on how I might be able to successfully sync this SQL table to MySQL without these errors.
Given the small size of the datasets involved I would select as CHAR(36) from SQL Server and store in a CHAR(36) in MySQL.
If you are able to control the way the data is inserted by Layer2 Cloud Connector then you could set your MySQLTable GUID column as BINARY(16) -
SELECT CAST(GUID AS CHAR(36)) AS GUID, OtherColumns FROM SQLTable;
INSERT INTO MySQLTable (GUID) VALUES (UUID_TO_BIN(GUID)))
SELECT BIN_TO_UUID(GUID) AS GUID, OtherColumns FROM MySQLTable;

Mysql 5.5.54 Duplicate entry on unique key with multiple columns

We have table in production (locally I try to do same thing, everything works as expected, maybe I have newer db version).
Table contains many columns, two of them is number AND year. These columns are bound with unique constraint key.
When I do query such as
SELECT * FROM `order` WHERE number IS NULL AND YEAR = 2018
I get more than one row. And it's not important, it's correct. [I could have 100 rows with null, 2018 for example]
But when I try to insert new record with number = null and year = 2018. I get error such as
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2018' for key 'number_year_UNIQUE'
One thing which comes in mind is that null in mysql is hiddenly bound with random number, and when I try to insert it's somehow becomes duplicate for new record.
As extra info is: We use Yii1 and error appears through ActiveRecord.
EDIT
After suggeestion added profiling got bound params
They are as follow
:yp13='2018',
:yp14='',
Exactly same parameters are on local machine.
EDIT
did you tried to run the insert query from from sql console(PhpMyAdmin or similar)?
I doubt it's an issue in the php side like the way you pass null value.
The problem was in that I tried to insert empty string '' not null value, as stated above (seen on screenshot).
In code I had something like
$order = new Order();
//some other stuff
$order->number = null;
$order->save();
However, in rules (in newly added validation method, number became empty string)
Added scenario (Yii specific) and problem had gone.

SSIS Lookup on data being imported

This is a classic does the record exist then update otherwise insert scenario. The dataflow process I am following is as follows:
OLE DB: return list of fields one of which is a calculated hashvalue on a number of the fields in the dataset
Lookup: See if the row has changed by comparing the hashvalue and another key field(allows duplicates) against the latest record in the target table for that key field.
If matches update the record, if no match then insert.
The problem I am having is that one of the records that I would match against is in the dataset I am importing and not in the target table. Therefore I always geta NO MATCH result. If I delete the row causing the error in the target table then re-run the import I do get a MATCH.
I have tried turning off the cache for the lookup with no success. Suffice to say I have searched for the answer with no luck. HELP

Update + Append Query in Access 2007

I'm working on a database right now and I have a pretty specific problem that I'm trying to figure out:
I have a large master table in my database with all the info we're gathering. We're updating records in this master table based on Excel files returned to us by various team members across the company - all of the records have unique ID numbers so we know what fields in the master table to update. We are tracking who responds by updating the file name into the master table as well. I want to update this with the file name; however, if two sources give me the same data, I want to append the second file to the first file rather than replace it with an update.
The problem is, I need the query to "know" when to update and when to append. Is there some IF statement I can use - maybe Update when Null, Append when Not Null?
You can refer to an Excel sheet or range in a query:
INSERT INTO Table1 ( ADate )
SELECT SomeDate FROM [Excel 8.0;HDR=YES;DATABASE=Z:\Docs\Test.xls].[Sheet1$a1:a4]
WHERE SomeDate Is Not Null
This means that you can run queries based on the presence or absence of data in the Excel file.

Filemaker Pro 10: How to get the unique ID of last insert on mySQL tables (ODBC)

I have a filemaker script that inserts a new entry on several imported mySQL tables. I need to get the unique id of these entries as they are created (before or after, either way) so I can refer to them later in the script. This is easy to do in SQL with LAST_INSERT_ID(), but I can't seem to find how in filemaker.
What I have tried that didn't work:
GetNextSerialValue ( Get ( FileName )&".fp7" ; "jos_users::id" ) #returns nothing, does not work properly on ODBC tables
Get(RecordID) #Local value does not correspond to the mySQL unique ID
Thanks in advance! Any suggestions are appreciated.
How are you creating the records in your MySQL table? Are you using FileMaker's ESS and native "New Record" command to insert the new record or are you using the Execute SQL[] script step? Or something different?
The next serial value and recordID values are FMP-specific and don't apply here (unless your MySQL primary key is a serial value managed by FMP).
With "New Record" FileMaker sets your record context to the new record. So if your "jos_users" table occurrence is an alias to the MySQL table, calling "New Record" will place you in the context of that record. You can then set a variable to the contents in the "id" column.
Go To Layout ["jos_users" (jos_users)]
New Record/Request
Commit Records/Requests[No dialog]
Set Variable [$lastInsertID; jos_users::id]
This presumes that your MySQL record is given a proper ID at record insertion time and that the record can be committed passing any validation checks you've applied.
If you're creating the records using some other process, let us know and we can advise you on how to get the value.