MariaDB, Convert VARCHAR to DECIMAL - mariadb

I have a column with VARCHAR i i want convert to DECIMAL for use after in a query in my vb project. But i don't find the correct syntax.
I try fisrt like mysql use :
SELECT
CAST(REPLACE(Espesor,',','.') AS DECIMAL (10,2)) AS TT
FROM Produccion
WHERE id = 153392
and i have 5,5 (Works fine).
But under MariaDB i the syntax is different. Is like this
DECIMAL[(M[,D])]
I Tried with the follow code :
SELECT
CAST(REPLACE(Espesor,',','.') AS DECIMAL[(10[,2])]) AS TT
FROM Produccion
WHERE id = 153392
and i have an error near [(10[,2])]) AS TT

The MariaDB SQL syntax is not different, it is just the documentation syntax that is.
Both MySQL and MariaDB allow to declare a column as DECIMAL without the parentheses, in that case default values are used for maximum number of digits, and number of decimals.
So DECIMAL is the same as DECIMAL(10,0).
The MariaDB documentation is just more formal about describing this, using EBNF syntax, where the square brackets are used to show that the enclosed parts are optional.
So DECIMAL[(M[,D])] is actually saying that the '(...)' part is optional, and furthermore that the ',D' part also is. So
DECIMAL
DECIMAL(10)
DECIMAL(10,0)
are all valid variants, and all work the same with MySQL and MariaDB.
Just use your MySQL code unchanged on MariaDB, and it will work just fine there.

It's finaly a problem with Visual Studio 2015 and my MYSQL updates.
I uninstall :
Mysql for Visual Studio 1.2.8
Mysql Connector Net 8.0.16
And install :
Mysql for Visual Studio 2.0.5 m4
Mysql Connector Net 6.9.9
And all works again.
Thanks

Related

Debezium Source - JDBC Sink - Precision Mode Connect and Infinity result in date out of range

I have Debezium in a container, capturing all changes of PostgeSQL database records. In addition a have a confluent JDBC container to write all changes to another database.
While the operation is in progress, after a while i am receiving the following error:
ERROR: timestamp out of range: "290303-12-10 19:59:27.6+00 BC"
My configuration on source about datetime:
"time.precision.mode": "connect",
After a carful investigation, I saw that inside the failing table there are dates with value '-infinity'...
Based on PostgreSQL documendation, infinity and -infinity exists:
PostgreSQL supports several special date/time input values for convenience, as shown in Table 8.13. The values infinity and -infinity are specially represented inside the system and will be displayed unchanged; but the others are simply notational shorthands that will be converted to ordinary date/time values when read. (In particular, now and related strings are converted to a specific time value as soon as they are read.) All of these values need to be enclosed in single quotes when used as constants in SQL commands.
I also see that this has been fixed on Debezium 1.5.0-Beta based on the Issue https://issues.redhat.com/browse/DBZ-2450 but i have Debezium 2.0.0. Lastly I see that now this is a JDBC issue and not Debezium so i tried to update JDBC from 10.4.0 to 10.6.0 but nothing changed.
Any ideas how I can fix that?

MariaDB insert error in PHP7 since upgrade from CentOS7 to Oracle Linux Server 8.6 [duplicate]

When using this query :
INSERT INTO order (order_quantity)
VALUES ('50')
I'm getting an error :
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 'order (order_quantity) VALUES('50')' at line 146
What's wrong with my query?
Reserved words are not recommended for use as database, table, column, variable or other object names. If you desire to use a reserved word is used as an object name in ANSI standard syntax, it must be enclosed in double-quotes to allow the Relational Engine (whichever that one is) that the word is being used as an object and not as a keyword in the given context.
Here are some examples specific to different SQL engines:
order is a SQL Keyword, used to sort results (ORDER BY ...)
Wrap backticks around it if you are using MySQL or Maria DB
INSERT INTO `order` (order_quantity) VALUES ('50');
Wrap brackets around it if you are using MS SQL Server
INSERT INTO [order] (order_quantity) VALUES ('50');
Wrap double quotes around it if you are using pgSQL
INSERT INTO "order" (order_quantity) VALUES ('50');
In example, nothing (but common sense) prevents you from creating a database named INSERT with a table INTO having a column VALUE(42)
Yes, this query works :
USE [INSERT];
SELECT [INTO].[VALUE(42)] FROM [INTO];

How to implement INSERT where not exists for ORACLE in Mule4

I am trying to implement a use-case in Mule4 where a tour needs to be assigned to a user if it has not already been assigned.
I was hoping that I could implement it using Mule db:insert component and using INSERT WHERE NOT EXISTS SQL script as below.
INSERT INTO TL_MAPPING_TOUR(TOURNO,TLID,SYSTEM) select :tourno,:tlid,:system from DUAL
where not exists(select * from TL_MAPPING_TOUR where (TOURNO=:tourno and TLID=:tlid and SYSTEM=:system))
However, this is resulting in Mule Exception
Message : ORA-01722: invalid number
Error type : DB:BAD_SQL_SYNTAX
TL_MAPPING_TOUR table has an id column (Primary Key), but that is auto-generated by a sequence.
The same script, modified for running directly in SQL developer, as shown below, is working fine.
INSERT into TL_MAPPING_TOUR(TOURNO,TLID,SYSTEM)
select 'CLLO001474','123456789','AS400'
from DUAL
where not exists(select * from TL_MAPPING_TOUR where (TOURNO='CLLO001474' and TLID='123456789' and SYSTEM='AS400'));
Clearly Mule db:insert component doesn't like the syntax, but it's not very clear to me what is wrong here. I can't find any INSERT WHERE NOT EXISTS example implementation for the Mule4 Database component either.
stackoverflow page https://stackoverflow.com/questions/54910330/insert-record-into-sql-server-when-it-does-not-already-exist-using-mule directs to page not found.
Any idea what is wrong here and how to implement this in Mule4 without using another Mule4 db:select component before db:insert?
I don't know "mule4", but this:
Message : ORA-01722: invalid number
doesn't mean that syntax is wrong (as you already tested it - the same statement works OK in another tool).
Cause: You executed a SQL statement that tried to convert a string to a number, but it was unsuccessful.
Resolution:
The option(s) to resolve this Oracle error are:
Option #1: Only numeric fields or character fields that contain numeric values can be used in arithmetic operations. Make sure that all expressions evaluate to numbers.
Option #2: If you are adding or subtracting from dates, make sure that you added/substracted a numeric value from the date.
In other words, it seems that one of columns is declared as NUMBER, while you passed something that is a string. Oracle performed implicit conversion when you tested the statement in SQL Developer, but it seems that mule4 didn't and hence the error.
The most obvious cause (based on what you posted) is putting '123456789' into TLID as other values are obviously strings. Therefore, pass 123456789 (a number, no single quotes around it) and see what happens. Should work.
SQL Developer is too forgiving. It will convert string to numbers and vise versa automatically when it can. And it can a lot.
Mulesoft DB connector tries the same but it is not as succefule as native tools. Pretty often it fails to convert, especially on dates but this is not your case.
In short - do not trust too much data sense of Mulesoft. If it works - great! Otherwise try to eliminate any intelligence from it and do all conversions in the query and better from the string. Usually number works fine but if doesn't - use to_number function to mark properly that this is the number.
More about this is here https://simpleflatservice.com/mule4/AvoidCoversionsOrMakeThemNative.html

Sqlite fts4 case sensitive

Very new to Sqlite3 and I finally have an FTS4 search working, but am stumped how to code for Case-Sensitive. I have a Database with tblMain that has two BLOB_TEXT columns, advOne and advTwo
CREATE VIRTUAL TABLE tFind USING FTS4(aOne, aTwo);
// populate tFind here
SELECT FROM tFind WHERE aOne MATCH 'Fine';
This works fast and returns records with
feeling fine and
a Fine was levied
I need to find the records with only the case sensitive Fine in them.
How do I word the line?
I am using Lazarus and Ubuntu if that makes any difference.
The default tokenizer ignores case.
You'd have to install your own custom tokenizer.

InvalidCastException for LINQPAD

I'm using LinqPad and IQ driver for SQLite. I have connection with this file. Look:
"Okreslone rzutowanie jest nieprawidlowe" - it can be simple translate to "invalid cast", but Zbiors.Count() return value 8.
When i'm trying do it in SQL query:
select * from zbior
Then all's ok. How can i get same result by "C#", not by SQL query?
Most likely, the types are incorrect. SQLite has a horrible "feature" whereby you can put strings into integer columns and vice versa. The column types are merely suggestion and are not enforced. So what looks like integers in your data might actually be strings, causing in InvalidCastException when the IQ driver tries to read them.

Resources