How to decode \xD6 to ö with asp classic? - asp-classic

I get a JSON string that contains the swedish character ö and I put it in the variable "adress", and when I just do response.write adress on the page it is displaying correctly the "ö", but when I try to insert it into my mysql db I get this error.
Microsoft OLE DB Provider for ODBC Drivers fel '80004005'
[MySQL][ODBC 3.51 Driver][mysqld-5.7.21-log]Incorrect string value: '\xD6STERS...' for column 'postadress' at row 1
I have set up the db so it can handle 4 characters and I can insert an emoji and that has 4 characters. The column "adress" is utf8mb4_swedish_ci
And on my server I have set this so that everything should be utf8mb4.
I have this in my mysql configuration file, my.ini
character-set-server=utf8mb4
collation-server = utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4’
init_connect='SET collation_connection = utf8mb4_unicode_ci’
skip-character-set-client-handshake
But since this isn´t working I guess that I have to decode the variable adress somehow?
So how can I decode a JSON string in asp classic?
Any input really appreciated, thanks.

Would this help...
'remove BOM if present
If (Len(Trim(adress)) > 0) Then
Dim AscValue : AscValue = Asc(Trim(adress))
If ((AscValue = -15441) Or (AscValue = 239)) Then : fileContent = Mid(Trim(adress),4) : End If
End If

Related

R: Data Frame is removing every other character from nvarchar/unicode fields

I have connected R to my database using the below:
con <- DBI::dbConnect(odbc::odbc(),
Driver = "/usr/local/lib/libmsodbcsql.17.dylib",
Server = "my server",
Database = "my db",
UID = "my uid",
PWD = "my pw",
Port = 1433)
but for every string (either table names or field values), every even character has been removed.
Example 1-:
dbListTables(con)
Returns:
SLn
However, the actual table name is 'SOLine'
Example 2 - Running a query using:
query<-paste0("SELECT SOOrder.AddressLine1, SOOrder.OrderDate, SOOrder.OrderTotal FROM SOOrder WHERE SOOrder.OrderNbr=1")
test_query<-dbGetQuery(con,query)
test query
Returns:
AddressLine1 OrderDate OrderTotal
Ts drs ie1 2019-10-28 100.00
When running the same query in SSMS returns:
AddressLine1 OrderDate OrderTotal
Test Address Line 1 2019-10-28 100.00
Therefore, integers and date-time are not affected. It solely appears to be strings: more specifically nvarchar (varchar types are not affected). Looking into the schema, they are Unicode fields.
Have not found a fix - but a good workaround is
CAST(Table.Column AS varchar) AS Column
This allows the complete column to successfully pull through.

while inserting i can insert danish character in proper format in sqlite Db but while retrieving my query returns no result

while inserting i can insert danish character in proper format in sqlite Db but while retrieving my query returns no result
String searchQuery= "SELECT * FROM article,product where article.ItemNo=product.ItemNo ";
if(searchText.length()>0)
{
searchQuery += " AND (article.itemNo like '"+ searchText +"%' OR product.Description like '"+ searchText +"%')";
}
in debug mode query is
`SELECT * FROM article,product where article.ItemNo=product.ItemNo AND (article.itemNo like '%ø%' OR product.Description like '%ø%')..`
No result returns
Proper query will be
SELECT * FROM article,product where article.ItemNo=product.ItemNo AND (article.itemNo like '%Ø%' OR product.Description like '%Ø%');
the desired description field value in Db is MØNTPUNG.
I am wondering is there any issue of case sensitivty?I am using UTF8 encoding for my raw file that will insert data to DB.
The documentation says:
SQLite only understands upper/lower case for ASCII characters by default. The LIKE operator is case sensitive by default for unicode characters that are beyond the ASCII range. For example, the expression 'a' LIKE 'A' is TRUE but 'æ' LIKE 'Æ' is FALSE.
To handle non-ASCII characters correctly, store an uppercase version of your string(s) in a separate column, and search in that with an uppercase search pattern.

SQllite Query with Lower and Special Characters

I have a Sqllite query
SELECT * FROM m_table WHERE LOWER(fName) = LOWER('yui!"'':;/?') AND account = '100' ORDER BY fName COLLATE NOCASE ASC ;
Above returns 0 rows; But when I use the same as below , it Works
update m_table set fName = 'yui!"'':;/? renamed' where fname='yui!"'':;/?' AND account = '100';
Any clues ?
PS: I am using LOWER to ignore case sensitive. I am using this via an android client. Hence
I am also doing StringEscapeUtils.escapeSql("folderName")
This is most likely related to the fact, that your input string contains characters in a non-ASCII-charset. from the documentation of SQLlite:
lower(X) -- The lower(X) function returns a copy of string X with all
ASCII characters converted to lower case. The default built-in lower()
function works for ASCII characters only. To do case conversions on
non-ASCII characters, load the ICU extension.
http://www.sqlite.org/lang_corefunc.html
Try to run the following statement and see what it returns.
SELECT LOWER(fName) FROM m_table WHERE fname='yui!"'':;/?' AND account = '100';

How to store a multi-line text in sql server 2005 using SSMS?

I got similar questions to this but not get satisfied answers. I want to store paragraph in table in sql server 2005. I tried all data types (nvarchar, varchar, text etc.) but when I copy the content, it store only 1st line. Help me.
I am using Sql Server Management Studio and directly copy paste the content into table. And for retrieving I use this code.
String query2 = String.Format("select data from try where roll=55");
SqlCommand cmd2 = new SqlCommand(query2, conn);
SqlDataReader reader2 = cmd2.ExecuteReader();
if (reader2.Read())
{
Label1.Text = reader2.GetValue(0).ToString();
}
where 'data' is multiline content.
I did a little test using Sql Server 2008-R2 (So it might be different on 2005):
insert into Test1 (Col1) VALUES('THIS
INSERTS
A
Multiline
String')
When selecting, the result DOES look like there are no line-breaks, BUT if you check for char(10) and char(13) - (CRLF) they DO exist in the string...
select col1, REPLACE(REPLACE(col1,CHAR(10), 'X'),CHAR(13), 'Y') as LineBreaks from Test1
Result:
If you set SSMS to return values as text rather than grid (button on toolbar) you can see the line breaks in the text, they aren't displayed in the grid view.
I have a web application that I help maintain, we store the data from a multiline textbox in SQL server 2008 R2 -- inserted with ADO.Net and Pulled using ADO.net At first glance it appears that the breaks in the "paragraph" are missing. To recover the line breaks for a printable version of the data, I utilize a quick regular expression to place the breaks back in the web app. The method used to do this is below:
public static string lineBreakCharsToHTMLBreak(string sourceString)
{
// This regex says look for any tab, carriage return or linefeed
Regex rexNewLine = new Regex("[\\t\\n\\r]");
sourceString = rexNewLine.Replace(sourceString, "<br>");
Regex rexDoppleBreak = new Regex("(<br>){2,}");
sourceString = rexDoppleBreak.Replace(sourceString, "<br>");
return sourceString;
}

Convert image into bytes to store in database

Can anybody tell me that how to convert an image (stored in a file path) into bytes to store in a database?
Why do you want to store the path as bytes? Why don't you just store it as a string? Unless you mean you want to store the image data as bytes in the database, in which case, look into the Image data type.
To convert an image stored locally to bytes you can use IO.File.ReadAllBytes(). To convert an image on the web you can use Net.WebClient.DownloadData(). The IMAGE data type is going away in SQL Server, so use VARBINARY(MAX) to store it.
Code:
Dim url As String = "http://example.com/image.png",
file As String = "c:\image.png"
Using connection As New Data.SqlClient.SqlConnection("your connection string"),
saveImage As New Data.SqlClient.SqlCommand("dbo.saveImage", connection)
connection.Open()
saveImage.CommandType = Data.CommandType.StoredProcedure
'use only one of these
saveImage.Parameters.AddWithValue("#imageData", New Net.WebClient().DownloadData(url)) 'get file from url
'saveImage.Parameters.AddWithValue("#imageData", IO.File.ReadAllBytes(file)) 'get file locally
saveImage.ExecuteNonQuery()
End Using
Procedure:
CREATE PROCEDURE [dbo].[saveImage] ( #imageData AS VARBINARY(MAX) )
AS
INSERT INTO dbo.myImage ( imageData ) VALUES ( #imageData )
Table:
CREATE TABLE [dbo].[myImage](
[imageData] [varbinary](max) NOT NULL
)

Resources