Why is equals involving MariaDB JSON not reflexive? - mariadb

The following MariaDB statement uses JSON_EXTRACT to turn the JSON-escaped string a into a JSON-typed value, and then this value is compared to itself. The comparison comes up as not equal. I thought that equality was reflexive (barring tricky things involving NULL and NaN), that is, a value is always equal to itself. What am I misunderstanding?
SELECT
JSON_EXTRACT('"a"', '$'),
JSON_EXTRACT('"a"', '$') =
JSON_EXTRACT('"a"', '$');
Server info:
Server: Localhost via UNIX socket
Server type: MariaDB
Server connection: SSL is not being used Documentation
Server version: 10.6.7-MariaDB-2ubuntu1-log - Ubuntu 22.04
Protocol version: 10
User: phpmyadmin#localhost
Server charset: UTF-8 Unicode (utf8mb4)

Apparently the solution is to use JSON_EQUALS(), which was added in MariaDB 10.7. I don't have an instance of MariaDB 10.7 so I can't test it, and dbfiddle only goes up to MariaDB 10.6.
You can, however, unquote the JSON to extract the string value, and test for equality.
SELECT
JSON_UNQUOTE(JSON_EXTRACT('"a"', '$')) AS a,
JSON_UNQUOTE(JSON_EXTRACT('"a"', '$')) =
JSON_UNQUOTE(JSON_EXTRACT('"a"', '$')) AS `a=a`;
a
a=a
a
1
https://dbfiddle.uk/?rdbms=mariadb_10.6&fiddle=6fa8c7156e6fe9213bfbf44dd57e2c63

Related

Why would a database work on one server, and only partially on another?

Sorry if this is a newbie question. I have been searching and can't seem to figure this out.
I am trying to move a PHP webapp from Plesk, to RunCloud. Both are hosted on a Digital Ocean server.
I exported the database from Plesk, and imported it into RunCloud. After updating the config, it only partially works. Some of the tasks read data, a few seem to write, but a majority just break it.
The strange thing is, if I point the config file to the Plesk server, the app works great using it as a remote database.
Here is from the PHPMyAdmin. The only thing that looks fishy is UNIX, vs TCP. But I cannot find a way to change RunCloud to UNIX.
I would copy the errors, but they are across the board. Any ideas? Thank you so much!
PHPMyAdmin Plesk Server:
Server: Localhost via UNIX socket
Server type: MariaDB
Server connection: SSL is not being used Documentation
Server version: 10.1.48-MariaDB-0ubuntu0.18.04.1 - Ubuntu 18.04
Protocol version: 10
User: prod#localhost
Server charset: UTF-8 Unicode (utf8mb4)
From RunCloud Server:
Server: 127.0.0.1 via TCP/IP
Server type: MariaDB
Server connection: SSL is not being used Documentation
Server version: 10.4.21-MariaDB-1:10.4.21+maria~focal-log - mariadb.org binary distribution
Protocol version: 10
User: prod#localhost
Server charset: UTF-8 Unicode (utf8)
As a newbie, I learned that 10.1 and 10.4 were rather different. I then went through each error to see if I could find the change on the MariaDB update guide (which is great). Somehow, I came across this post: error code 1292 incorrect date value mysql. It was the zero date. I just added the line in my.cnf that it suggested. Fixed!!!

How to update/insert Cyrillic data in MySQL DB (Windows 10, XAMPP CP v3.2.4)?

I observe a strange situation in Windows 10 with XAMPP Control Panel v3.2.4
Terminal window is launched and connected to Mysql DB.
Note: prior in terminal window issued command 'chcp 65001' to support UTF8 encoding.
Now when I attempt to update some table with value which is in Cyrillic then MySQL complains about not closed quote symbol. If I replace Cyrillic input to English then command is accepted.
MariaDB [youtube]> update episodes set name='Катя' where id=11;
'>
If I attempt to insert a new record into DB same situation happens
MariaDB [youtube]> insert into episodes (youtube_id,series_id,season,episode,name) values (12345678904,1,0,1,'Катя');
'>
If double quotes are used situation is the same
MariaDB [youtube]> insert into episodes (youtube_id,series_id,season,episode,title) values (12345678904,1,0,1,"Катя");
">
What a magic touch required to make it work through terminal window?
Update:
John suggested to look into configuration file of MariaDB for UTF8 settings.
The settings was changed to the following and the problem still persists
# The MySQL server
default-character-set=utf8mb4
[mysqld]
init-connect=\'SET NAMES utf8\'
character_set_server=utf8
collation_server=utf8_unicode_ci
skip-character-set-client-handshake
character_sets-dir="C:/bin/XAMPP/App/xampp/mysql/share/charsets"
Initially settings was
# The MySQL server
default-character-set=utf8mb4
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
Server status report
MariaDB [youtube]> \s
--------------
mysql Ver 15.1 Distrib 10.4.10-MariaDB, for Win64 (AMD64), source revision c24ec3cece6d8bf70dac7519b6fd397c464f7a82
Connection id: 17
Current database: youtube
Current user: root#localhost
SSL: Not in use
Using delimiter: ;
Server: MariaDB
Server version: 10.4.10-MariaDB mariadb.org binary distribution
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: utf8
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
TCP port: 3306
Uptime: 11 min 12 sec
Threads: 7 Questions: 59 Slow queries: 0 Opens: 22 Flush tables: 1 Open tables: 16 Queries per second avg: 0.087
--------------
MariaDB Documentation has reference to an option --default-character-set=name.
An attempt to use --default-character-set=utf8mb4 on command line had no effect on behavior of insert/update record in terminal client.
mysql -u root -p --default-character-set=utf8mb4 youtube
....
MariaDB [youtube]> update episodes set title='Катя' where id=11;
'>
I highly recommend getting a copy of the freeware program HeidiSQL. It's not perfect and even crashes occasionally though compared to everything else I've worked with? Oh boy, totally worth my time.
Secondly you want to make sure that you're using the following:
Database Character Set: utf8mb4
Database Collation: utf8mb4_unicode_520_ci
These have the greatest UTF-8 support from what I've read from Stackoverflow member Rick James, via his website. He's a database superstar here on SO so if you ever hire him dump buckets of money on his face. His site has a comparison chart. In fact it's been a while and 520 might have been superseded since I last checked.
To set/change the Database Character Set you will need to change the my.cnf configuration file for MariaDB, I recommend using Notepad++ for code editing. This should make any newly created databases use the correct encoding however you may have to go through and manually update the character sets and collations for databases, tables and table columns so do not forget to be thorough!
[client]
default-character-set = utf8mb4
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_520_ci
Once you do that your queries with Russian/Greek/etc should work normally as they do with English. Keyword: should.
Since I only speak two languages (English and bad English) I encode all characters past a certain Unicode numeric point just to be certain. It'll take up a bit more space however there are sometimes characters added for languages to Unicode after the majority of the language has been defined thus potentially fragmenting language support. If you're interested comment and I'll go find that code for you.
I'm at a moderate level of comprehension and I'm no Rick James though I have about two or three dozen translation pages (use the search feature and search for 'translation') on the site in my profile if you want to see the output. After I did these things I stopped having the data get corrupted. I hope this helps!

ViciDial: MyISAM Specified key was too long; max key length is 1000 bytes

I have installed MariaDB in a Ubuntu 14.04 and trying to run some scripts that the main solution provides (ViciDial). When I try to execute the Sql file, it gives an error in the following CREATE TABLE statement:
CREATE TABLE www_phrases (
phrase_id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
phrase_text VARCHAR(10000) default '',
php_filename VARCHAR(255) NOT NULL,
php_directory VARCHAR(255) default '',
source VARCHAR(20) default '',
insert_date DATETIME,
index (phrase_text)
) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;
The error is:
ERROR 1071 (42000) at line 3348: Specified key was too long; max key length is 1000 bytes
MariaDB status:
MariaDB [DialerDB]> status;
--------------
mysql Ver 15.1 Distrib 10.0.38-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
Connection id: 53
Current database: DialerDB
Current user: root#localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 10.0.38-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 1 hour 15 min 49 sec
As far as I understand the limit in MyISAM is 1000, and in newer versions is around 3200, so if the varchar is 10000 this is an error, correct?
But this software is installed correctly if done via installer (an ISO image) and the DB tables are the same...so there must be some config limiting my MariaDB to do this.
Any idea?
If that column has "text" in it, suggest looking into a FULLTEXT index; it will search for words quite efficiently.
A compilation of the limits is here; 10K won't work for a simple index.
(Meanwhile, you should move from MyISAM to InnoDB.)

mysql window function working on production server, not on Raspberry Pi

I have just setup my Raspberry Pi (RPI) with OSMC (debian 9 stretch), nginx, PHP 7, Mysql and phpmyadmin
All seems to be working except the mysql windows functions. For example the following query produces a syntax error:
SELECT sum(propertyId) over() FROM `properties`;
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '() FROM `properties` LIMIT 0, 25' at line 1
However, the exact same query and database tables works fine on my production server.
Here are the setups (from the respective phpmyadmins) for the two servers:
RASPBERRY PI (not working)
Database server
Server: Localhost via UNIX socket
Server type: MariaDB
Server version: 10.1.26-MariaDB-0+deb9u1 - Debian 9.1
Protocol version: 10
User: phpmyadmin#localhost
Server charset: UTF-8 Unicode (utf8)
Web server
nginx/1.10.3
Database client version: libmysql - mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $
PHP extension: mysqliDocumentation mbstringDocumentation
PHP version: 7.0.30-0+deb9u1
PRODUCTION SERVER (WORKING FINE)
Database server
Server: Localhost via UNIX socket
Server type: MariaDB
Server version: 10.2.12-MariaDB-log - MariaDB Server
Protocol version: 10
User: montegoventures#localhost
Server charset: UTF-8 Unicode (utf8)
Web server
cpsrvd 11.70.0.53
Database client version: libmysql - 5.1.73
PHP extension: mysqliDocumentation curlDocumentation mbstringDocumentation
PHP version: 5.6.30
I have tried countless times to upgrade the mariadb on the RPI to version 10.2 but no matter what I do, it still installs version 10.1.26
So, any suggestions on how I can get my simple query to work on my RPI server? Yes, I know it is a trivial query, but if I can't get that simple one to work on the RPI, how can I get my complex queries to work?
thanks

Although freetds.conf set to charset UTF-8, pyodbc fetchall returns in unicode?

I am using pyodbc, ODBC with freetds to access a remote MSSQL database. I recently migrated from Centos + Python 2.4 to Ubuntu + Python 2.7 and the two are behaving differently. My freetds.conf is:
[global]
# TDS protocol version
tds version = 4.2
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
[server]
host = server
port = 1333
tds version = 8.0
client charset = UTF-8
My Python code is (simplified):
import pyodbc
msConn = pyodbc.connect('DSN=%s;UID=%s;PWD=%s' % (self.dsn, self.user, self.passwd))
msCur = msConn.cursor()
msQuery='''select ...'''
msCur.execute(msQuery % startUpdateStamp)
for row in msRows:
print rows
When I execute the code above on my Centos server (with python 2.4), any special characters are encoded in utf-8. However when executing the same code with same configuration on the Ubuntu server (python 2.7), the special characters are in unicode. It is as if the configuration client charset = UTF-8 is being completely ignored.
However I've tried setting client charset to other values, in return the server does not allow the connection. Which means the client charset setting is getting through. I have also tried changing the tds version = 8.0 to no avail.
I've also looked here, but the answer does not explain why given the same database, two systems give two encodings.
How can I have the Ubuntu return UTF-8 as well?
I'm not proficient at MSSQL or ODBC. Any help is greatly appreciated.

Resources