I am using Visual Foxpro 9 with SQL Server as back-end. I am executing this query to update an existing column value with a unicode text:
UPDATE <table> SET fname = "N('" + hexchr + "')"
The problem is Foxpro is storing string as:
N(0945;0987;)
whereas when the same command is run via SQL Server management studio, the string is stored as actual devnagari font.
How to make Foxpro execute the above query with the N?
I've never tried working with Unicode and feeding SQL-Server... However, with respect to helping prevent SQL-Injection, in VFP, when using SQL-Passthrough (SQLConnect(), SQLExec(), etc), If you write your query with "?" place-holder, it will look at the VARIABLE from within VFP... such as
myField = 0x123 && or whatever hex value... VFP leading with 0x implies hex
myKey = "whatever"
cSQLCmd = "update SomeTable set Field1 = ?myField where SomeKey = ?myKey"
nSQLHandle = sqlconnect( YourConnectionStringInfo )
SQLExec( nSQLHandle, cSQLCmd )
sqldisconnect( nSQLHandle )
VFP will handle the ? parameters for you by their respective found variable names that are available. Now, all that being said, VFP was only based on 32 bit, and don't believe it recognizes "unicode" values. What you may need to do is create a stored procedure in SQL that accepts two hex value (or whatever), and call that and pass it in as so required.
Related
I don't think title could be more described better as tl;dr, because problem is a bit deeper.
I've got two databases (finnish language):
MSSQL (collation: SQL_Latin1_General_CP437_CI_AI)
MySQL (collation: utf_general_ci)
I've created BI project in vs2017, connected two databases and transfered tables from one to another, no problem. Except for 1 letter: "å" - instead it was "?". I cannot change any database collation so I am trying to find a way to transfer words with this letter.
What I've tried:
OLD DB Source -> ODBC Destination
Point "1" with "Data Conversion" block in between (with code page 1252)
Script Component, in which I have tried:
Insert with "_latin"
sql= "INSERT INTO db.words(Name) VALUES(_latin1'å')";
byte[] b = Encoding.UTF8.GetBytes(sql);
odbcCmd = new OdbcCommand(Encoding.UTF8.GetString(b), odbcConn);
odbcCmd.ExecuteNonQuery();
Insert without it
sql= "INSERT INTO db.words(Name) VALUES('å')";
byte[] b = Encoding.UTF8.GetBytes(sql);
odbcCmd = new OdbcCommand(Encoding.UTF8.GetString(b), odbcConn);
odbcCmd.ExecuteNonQuery();
Diferent ways of encoding
byte[] bytes = Encoding.GetEncoding(1252).GetBytes("å");
var myString = Encoding.GetEncoding(1252).GetString(bytes);
byte[] bytes2 = Encoding.Default.GetBytes("å");
var myString2 = Encoding.Default.GetString(bytes2);
Insert with COLLATE which got me error
insert into db.words(Name) values ("å" COLLATE latin1_swedish_ci) ;
and error:
System.Data.Odbc.OdbcException: „ERROR [HY000] [MySQL][ODBC 5.3(a) Driver][mysqld-5.7.21-log]COLLATION 'latin1_swedish_ci' is not valid for CHARACTER SET 'cp1250'”
Here is interesting part:
I can make insert with this letter in MySQL Workbench without a problem, and it will be inserted, but when I try to pass it from one database to another it is lost. I've set Data Viewers between Data Conversion and the letter was still there, and also when debugging script it was after encoding in string that were inserted to database.
Maybe someone got any idea what else I can try, because I feel like I have tried everything, and feel that the resolve of this problem is really close, but I just don't see it.
CP1250 does not include å; CP437 and utf8 do include it.
COLLATE is irrelevant -- it applies only to comparing and sorting.
Don't use any encode/conversion functions; instead, specify how the data is encoded.
I see 'code' -- but what is the encoding for the source in that language and/or editor?
Show us the hex of any strings in question.
Which direction are you trying to transfer?
What are the connection parameters for each database?
This code works when the connection is made to an accdb database:
Dim customer = connection.Query(Of Klantgegevens)("Select Actief,Onderhoudscontract From Klantgegevens Where Klantnummer=#Idx", New With {.Idx = customerId}).SingleOrDefault
But the code below gives the error about the Idx parameter when the connection is made to a SQL server database that has a table with the same structure:
Dim customer = connection.Query(Of Klantgegevens)("Select Actief,Onderhoudscontract From [dbo.Klantgegevens] Where Klantnummer=#Idx", New With {.Idx = customerId}).SingleOrDefault
What is going wrong here? I had hoped that by using Dapper I would be able to write database agnostic code. But it seems that is not the case!
If you are using an ODBC/OLEDB connection, then my first suggestion would be: move to SqlClient (SqlConnection). Everything should work fine with SqlConnection.
If you can't do that for some reason - i.e. you're stuck with a provider that doesn't have good support for named parameters - then you might need to tell dapper to use pseudo-positional parameters. Instead of #Idx, use ?Idx?. Dapper interprets this as an instruction to replace ?Idx? with the positional placeholder (simply: ?), using the value from the member Idx.
This is also a good fix for talking to accdb, which has very atypical parameter usage for an ADO.NET provider: it allows named parameter tokens, but all the tokens all replaced with ?, and given values from the positions of the added parameters (not via their names).
I read the data line by line or stream it into a String (cHTML) then using a TADOQuery I use a simple Update or insert query
UPDATE Tablename
Set cFieldName = cHTML,
Where a = b
The cHTML is basically the HTML file's contents
The errors I get are when a colon in an URL is found the ADO thinks it is a parameter eg: <a href="https://www....
Other problems I get are where single quotes in the text at places like the word we've causes the string to not having a closing quote.
Does anyone know how to read an html file's contents into a SQL Server 2008 database using Delphi.
Use parameters something like this:
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('UPDATE Tablename SET FieldName = :P0');
ADOQuery1.SQL.Add('WHERE a = :P1');
ADOQuery1.Parameters.ParamByName('P0').Value := cHTML;
ADOQuery1.Parameters.ParamByName('P1').Value := c;
ADOQuery1.ExecSQL;
I wrote the vba code below:
For x = 1 To Anno.Options.Length
If Anno.Options(x).Text = CStr(LU(2, CL)) Then
Anno.selectedIndex = x
Exit For
End If
Next x
It takes the values of "LU(2, CL)" (from a query in mySql) and uses it to find the option to activate.
Usually it works, but if I set the values as "unsigned" in the database, no longer works and I get the error: " Variable uses an Automation type not supported in Visual Basic " (This is a translation of the error message in Italian)
Here's my question:
Is there a way to use "unsigned" type with excel?
Edit (clarifications):
LU is an array (type variant) that takes values with: LU = rs.getrows (where rs is a recordset resulted from a query on mySql)
If I modify the MySql database table by setting the field as "unsigned" (I'm talking about one of the fields acquired in LU by the query in the vba code) I get the error.
I'm trying to debug an old VB6 program at my job. It's full of bugs and hardcoded stuff.
The program is connecting on a SQL Server 2005 database to read and write info using stored procedures.
Since the program is still being used while I'm working on it, I made a backup of the database to test some things and restored it in my version of SQL Server 2008. Everything was working fine.
When I came in the next morning, I got an error I didn't have the previous night even though the program wasn't used in the night.
The problem :
"exec dbo.sp_Get_Wait_Data '" & DateEx & "'"
DateEx is a string containing "2012/06/14"
The stored procedure :
[sp_Get_Wait_Data] #Datest as char(10)
AS
SELECT
(A lot of column names here)
FROM
Fiche
LEFT JOIN
voyage ON fcid = vofiche
LEFT JOIN
client on fcaccount = cusnov
WHERE
fcdate = #Datest
AND (void is null or (void > 0 and (void <> 999 and void <> 1000 and void <> 998)))
AND ((fcremarques NOT LIKE '%SYSANNULATION%' OR
fcremarques IS NULL)
AND fcrettime IS NOT NULL)
ORDER BY
FcTime, FcOrgSite, fcdessite
The error message :
The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value
So the error is here fcdate=#Datest in the stored procedure. I tried adding this line in the stored procedure
SELECT convert(datetime, #Datest, 120)
which worked like a charm for the convertion within the query but caused a few hundred other errors within the program when other queries tried to access this variable so it is not an option.
Any idea why this query was working perfectly yesterday and now it's giving me this error? Thanks in advance.
You probably have set dateformat dmy when connecting to the copy of your database. The date format is set implicitly by the language used. set language.
You could change the format of the parameter to YYYYMMDD which will be safe regardless of set dateformat or even better, change your parameter to datetime.
If that is not an option you can rewrite your query using where fcdate=convert(datetime, #Datest, 111)