Paste to mysql CLI does not work - it loses some characters - mysql

I paste a >2KB SQL file to mysql CLI and it randomly loses characters and then reports syntax error in my SQL.
For example:
(.....)
UPDATE ct_transform_target_summary
SET
ytd_margin_target = jul_margin_target + aug_margin_target + sep_margin_target + oct_margin_target + nov_margin_target + dec_margin_target +
jan_margin_target + feb_margin_target + mar_margin_target + apr_margin_target + may_margin_target + jun_margin_target,
ytd_adjustments = jul_margin_adj + aug_margin_adj + sep_margin_adj + oct_margin_adj + nov_margin_adj + dec_margin_adj +
jan_margin_adj + feb_margin_adj + mar_margin_adj + apt_margin_adj + may_margin_adj + jun_margin_adj,
ytd_margin = jul_margin + aug_margin + sep_margin + oct_margin + nov_margin + dec_margin +
jan_margin + feb_margin + mar_margin + apr_margin + may_margin + jun_margin;
(....)
Becomes:
(....)
->
->
-> SET
-> ytd_margin_target = jul_margin_target + aug_margin_target + sep_margin_target + oct_margin_target + nov_margin_target + dec_margin_target +
->
-> ytd_adjustments = jul_margin_adj + aug_margin_adj + sep_margin_adj + oct_margin_adj + nov_margin_adj + dec_margin_adj +
-> jan_margin_adj + feb_ma
-> ytd_margin = jul_margin + aug_margin + sep_margin + oct_margin + nov_margin + dec_margin +
-> jan_margin + feb_margin + mar_margin + apr_margin + may_
This apparently never happens to short SQL code, but only happens to long code.
Could this be caused by my terminal (Fedora 17 Gnome terminal) or could it be an issue of mysql CLI?
Never had I experienced such problem in terminal before. It only happens in mysql cli.

Write the SQL to a file, ie: query.sql, then use the source command in the mySQL CLI.
$ vi query.sql
$ mysql -h db.host.tld -u user -p
mysql> use mydatabase
mysql> source query.sql

Pasting into the MySQL CLI client is tricky, because it uses Readline for interactive line editing. Readline interprets certain input as control sequences and does not pass them verbatim to the MySQL client. The character most likely to be causing problems in your case is tabulation, used often for indentation purposes in SQL, but used in Readline for tab completion. Inadvertent tab completion in the middle of your query might have very unexpected results and it is often hard to pinpoint the exact location where it has introduced interference.

I think Sammitch is on the right track here, but I believe that solution only works if you are logged into the machine where mysql is living. The following should work from anywhere.
$ vi query.sql
$ mysql -h db.host.tld -u user -p mydatabase < query.sql
Pasting into the CLI always makes me nervous!

Does this happen when you paste to a file in your terminal on your mysql server? Most likely you are having a buffer issue when pasting across the network. But I would check pasting to a file on the same server and if that works, then it is the mysql cli that is causing some issue, but I bet it's just the network latency causing problems.

Related

Disable camel-debezium-mysql endpoint URI in Camel metrics

The full Debezium MySQL URI string shows up in metrics. It shows the MySQL user and password in plaintext, which is unsafe. How can one disable this? I followed this setup here.
More information:
Using quarkus 1.11.1.Final which uses camel 3.7.0 with debezium-connector-mysql 1.3.1.Final
This is the Camel route:
from("debezium-mysql:" + config.getConnectorName()
+ "?databaseHostname=" + config.getHost()
+ "&databasePort=" + config.getPort()
+ "&databaseUser=" + config.getUser()
+ "&databasePassword=" + config.getPassword()
+ "&databaseServerName=" + config.getDatabaseServerName()
+ "&databaseServerId=" + config.getDatabaseServerId()
+ "&databaseIncludeList=" + config.getDatabases()
+ "&tableIncludeList=" + config.getTables()
+ "&columnIncludeList=" + config.getColumns()
+ "&databaseHistoryFileFilename=" + config.getHistoryFile()
+ "&offsetStorageFileName=" + config.getStorageFile()
+ "&exchangePattern=InOnly")
.routeId("debezium")
.process(outgoingProcessor)
.marshal().json(JsonLibrary.Jackson)
.to(ExchangePattern.InOnly, outgoingUri)
.to("micrometer:counter:outgoing.counter")
.end();
And when accessing the metrics at /q/metrics, I find this entry:
# HELP CamelExchangeEventNotifier_seconds_max
# TYPE CamelExchangeEventNotifier_seconds_max gauge
CamelExchangeEventNotifier_seconds_max{camelContext="camel-1", endpointName="debezium-mysql://entire connection string here with user and password", eventType="ExchangeCompletedEvent", failed="false", serviceName="MicrometerEventNotifierService",} 0.0
Thank you for bring this up. I have created a Jira ticket to fix this in the upcoming Camel release to mask those sensitive data in those events in the metrics.

Message Prompts not showing on Mobile Device

I have some script for my Google Sheet that returns a message prompt to the user when an action is completed...
Browser.msgBox('Inspection has been ADDED',
'Grower: ' + strIEGrower + '\\n' +
'Farm: ' + strIEFarm + '\\n' +
'Block: ' + strIEBlockNumber + '\\n' +
'Crop: ' + strIECropType,Browser.Buttons.OK);
It works fine when using the sheet on a desktop. But when I use it on a Mobile device the prompt does not show the prompt and my script errors with a timeout. I have tried using the...
SpreadsheetApp.getUi().alert('Complete');
It does not display either. Any help to display a message pop-up on a Mobile device would be appreciated.

Remote Desktop using VB from access

I have a table inside that table 3 Columns {USERNAME,PASSWORD,IP}
I want to use that data to remote anyPC inside my network instead open the remote desktop and enter the user,pass and ip .
I used that code but that makes me open the remote desktop for an IP , but the user and password doesn't insert well.
That is my VB code
Private Sub Toggle133_Click()
Shell ("cmdkey /generic:TERMSRV" + ip.Value() + "/user:fourtex\" + Text126.Value() + "/pass:" + Text109.Value() & "mstsc.exe /v " + ip.Value())
Shell ("mstsc.exe /v " + ip.Value())
End Sub

Getting the "Arguments are of the wrong type..." exception just by assigning query text

I have downloaded and installed MySQL Connector 5.1 x64 so I can use MySQL with Delphi. I can make connection with ODBC and do a connection from my Delphi environment and from MySQL Workbench.
But, when I build my Query at runtime, I get an error saying:
Project AAA.exe raised exception class EOleException with message 'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another'. Process stopped. Use Step or Run to continue.
My code:
qDates := TADOQuery.Create(Component);
qDates.Connection := FConnection;
qDates.SQL.Text :=
'select ' +
' * ' +
'from ' +
' resulttable ' +
'where ' +
' oid = :oid ' +
' and datedial >= :datebegin and datedial <= :dateend'; // <<-- Exception here
Details:
The exception happens right on the text assignment, before I have a chance to configure parameters.
If I comment out the where clause the assignment goes fine.
This is similar to Using parameters with ADO Query (mysql/MyConnector) but the difference is that I assign whole text at once and I get the exception before I have a chance to configure parameters.
The puzzling part - exact same code works fine on my other machine, but I can not figure out what is different.
Hence the question - what could cause the above exception outside of the Delphi code and MySQL server?
This seems to be a quirk with the MySQL ODBC provider.
If you assign the connection after setting the SQL text, then it will work.
The reason why can be found here.
qDates := TADOQuery.Create(Component);
// do net yet assign TADOConnection to prevent roundtrip to ODBC provider
qDates.SQL.Text :=
'select ' +
' * ' +
'from ' +
' resulttable ' +
'where ' +
' oid = :oid ' +
' and datedial >= :datebegin and datedial <= :dateend';
qDates.Connection := FConnection;
UPDATE
This QC entry explains the exact reason for this problem.
In short, the ADODB unit, patch this line from the RefreshFromOleDB procedure :
Parameter.Attributes := dwFlags and $FFFFFFF0; { Mask out Input/Output flags }
To:
if dwFlags and $FFFFFFF0 <= adParamSigned + adParamNullable + adParamLong then
Parameter.Attributes := dwFlags and $FFFFFFF0; { Mask out Input/Output flags }

How to trace MySql queries using MySql-Proxy?

I just downloaded the mysql-proxy and created this script lua (found in Mysql docs):
function read_query(packet)
if string.byte(packet) == proxy.COM_QUERY then
print("QUERY: " .. string.sub(packet, 2))
end
end
This is the command-line I'm using:
mysql-proxy -P localhost:1234 -b localhost:3306 --proxy-lua-script=profile.lua --plugins=proxy
When I run a simple query (like "select * from table1"), this error is reported: "failed: .\lua-scope.c:241: stat(C:...\profile.lua) failed: No error (0)"
Note: If I run mysql-proxy without lua script, no error occurs.
I need to install something to get mysql-proxy and query tracing working?
My environment is Windows 7 Professional x64.
Sorry the bad english.
The error you're getting is caused by --proxy-lua-script pointing to a file that mysql-proxy can't find. Either you've typed the name in wrong, you've typed the path in wrong, or you are expecting it in your CWD and it's not there. Or actually, looking at the entire error a little more closely, it seems possible that mysql-proxy itself sees the file in CWD itself OK, but one of the underlying modules doesn't like it (possibly because mysql-proxy changes the CWD somehow?)
Try saving profile.lua to the root of your C: drive and trying different versions of the option like so:
--proxy-lua-script=c:\profile.lua
--proxy-lua-script=\profile.lua
--proxy-lua-script=/profile.lua
One of those would probably work
simple query log lua script:
require("mysql.tokenizer")
local fh = io.open("/var/log/mysql/proxy.query.log", "a+")
fh:setvbuf('line',4096)
local the_query = "";
local seqno = 0;
function read_query( packet )
if string.byte(packet) == proxy.COM_QUERY then
seqno = seqno + 1
the_query = (string.gsub(string.gsub(string.sub(packet, 2), "%s%s*", ' '), "^%s*(.-)%s*$", "%1"))
fh:write(string.format("%s %09d %09d : %s (%s) -- %s\n",
os.date('%Y-%m-%d %H:%M:%S'),
proxy.connection.server.thread_id,
seqno,
proxy.connection.client.username,
proxy.connection.client.default_db,
the_query))
fh:flush()
return proxy.PROXY_SEND_QUERY
else
query = ""
end
end