I have an existing SQL Server database where text is stored in Arabic. The default database collation is FRENCH_CI_AS, but the application uses Arabic. Displaying the data with ASP is not a problem, but I want to create a new database using UTF-8!
Text sample as it's stored in database :
ترأس وزير السكن والعمران ووزير الأشغال العمومية للجنة التقنية لمراقبة البناء
How I can transform text to get clear Arabic text in the database ?
Is there a solution using Excel? http://en.file-upload.net/download-10245297/test.xls.html
first of all use nvarchar() for type of Data in your Tables then when inserting data into your tabel insert like this
string Query="insert into tablename(columnName) values(N'value')...";
The strings need to be stored in the database as NVARCHAR instead of VARCHAR. This allows the database to store UTF16 encoded strings instead of ASCII with a CodePage. Of course this will double the amount of storage needed for the database.
From the screen shot it looks like the string is UTF8 being displayed as if it was ASCII and there does not appear to be a way to tell SQL this detail.
I share a little java project (with dependencies).
This project loads table data first and formats strings. The generated EXCEL worksheet can now imported using SSMS.
Java solution :
String charabia = "ترأس وزير السكن والعمر" ;
try {
String utf8String = new String(charabia.getBytes(), "UTF-8");
} catch (UnsupportedEncodingException e) {
}
My project download link : here
Related
i try to input unicode character like " សួស្តី " into database via summernote but in database it display ??? instead of the unicode caracter, in database colliation i use latin_general_bin2 since the before i use summernote it could display unicode correctly, sorry may i know the correct way to do this.
above image is data inputed in database
and this is the data that i submit before it in database
and this is collation that i used
My database is divided into two parts: language-independent part and localizable part (containing Unicode text strings). For our translation staff it's much more easier to work not with some DB viewing tool but with some text format like JSON (via some tool of course). So I'm looking for a best way to load JSON data into my SQLite database. For now I use the foolowing approach (assume that I already have empty SQLite database):
I deserealise JSON data into C# classes (via Newtonsoft.JSON.dll).
For each of them I manually create INSERT command with paremeters (via System.Data.SQLite.dll) and then fill that parameters with class fields' values
I execute that command.
Is that correct (easiest, reliable) aproach to fill SQLite database with JSON data? Maybe I've missed some useful API?
Any other easily-readable text format (with Unicode support!) which is better to work with in term of C# and SQLite is welcomed.
Try Sqlite.NET, a basic Sqlite client and ORM: https://github.com/praeclarum/sqlite-net
From their wiki:
Once you have defined your entity, you can automatically generate
tables in your database by calling CreateTable:
var db = new SQLiteConnection("foofoo");
db.CreateTable<Stock>();
db.CreateTable<Valuation>();
You can insert rows in the database using Insert. If the table
contains an auto-incremented primary key, then the value for that key
will be available to you after the insert:
public static void AddStock(SQLiteConnection db, string symbol) {
var s = db.Insert(new Stock() {
Symbol = symbol
});
Console.WriteLine("{0} == {1}", s.Symbol, s.Id);
}
Similar methods exist for Update and Delete.
You would get something like this:
AddStock(string jsonString){
var stock = JsonConvert.DeserializeObject<Stock>(jsonString);
db.Insert(stock);
}
I'm trying to create a script that insert some rows in a table that has an xml saved as IMAGE type. The xml is using utf-8 format.
When I test with some text with accents, I just got the "illegal character" error on XML reading (via XmlDocument in c#).
So I want some way to convert an string with accent to a utf-8 format.
Example: when I save via XmlWriter (in c#) a string that contains "ã", it auto-converts it to "ã" to represent that character when saving on the database. And it works perfectly!
But I want to do it in a SQL Script.
So let's say the word "São Paulo", it saves "São Paulo". But using only SQL Server (script), I just can't make the xml valid with the word "São Paulo".
Only for more tech details, I'm working with a specific varchar/nvarchar that has this problem, so I just need to convert an text to a "unicode" or "utf-8" text that is valid on xml reading. And using Oracle worked fine, as it saves with accent and reads normally (using BLOB type), but I need the same script on SQL Server too.
I already tried some collates, converts and casts that I've found on the web but nothing worked for me.
Anyone know anything I can do?
Note: a thousand of replaces is not a solution.
Please try this:
CREATE TABLE testXML(test XML);
GO
INSERT INTO testXML(test) VALUES ('<root><r>plain text</r></root>')
,('<root><r>São Paulo</r></root>');
GO
SELECT x.y.query('.'), x.y.value('.','varchar(max)')
FROM testXML
CROSS APPLY test.nodes('/root/r') AS x(y);
GO
DROP TABLE testXML;
/*
Result
<r>plain text</r> plain text
<r>São Paulo</r> São Paulo
*/
Here the same with IMAGE and a lot of casting around. delivers the same result:
CREATE TABLE testXML(test IMAGE);
GO
INSERT INTO testXML(test) VALUES (CAST(CAST('<root><r>plain text</r></root>' AS XML) AS VARBINARY(MAX)))
,(CAST(CAST('<root><r>São Paulo</r></root>' AS XML) AS VARBINARY(MAX)));
GO
SELECT x.y.query('.'), x.y.value('.','varchar(max)')
FROM testXML
CROSS APPLY (SELECT CAST(CAST(test AS VARBINARY(MAX)) AS XML)) AS tbl(x)
CROSS APPLY tbl.x.nodes('/root/r') AS x(y);
GO
DROP TABLE testXML;
I am storing arabic text in sqlite database in my wp8 app. Below is an example of the arabic text stored in the sqlite file.
ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِينَ
The user would be able to search like below:
الحمد
this should return the above text, but I know in normal it doesn't.
I am using very simple query in sqlite
select * from tbl where ArabicText like '%الحمد%'
and in c#
query = "select * from tbl where ArabicText like '%"+textToSearch+"%'"
The result is zero records, How should I search to retrieve the above single record?
Thanks!
The easy answer, is to just use base64_encode on queries going into the database, and decode on information coming out (both while saving and while searching). It's not elegant, but it allows UTF characters into a non-UTF database.
Is there a way to get the actual encoded string saved in the Database of column with DataType Bytea. Because when the record is fetched in C# it returns as System.Byte[] which I don't want. I want the data which is saved in that column
E'\\\142\\\247\\\ and so on till the data ends.
I will appreciate your support
When I am querying the data through
SELECT tpl::TEXT from Cards where ecode="xyz";
I get the following error
Error: Cannot cast type bytea to text
Line1: Select tpl::TEXT from cards
Thank you
Like this
As you see that the Bytea column is showing System.Byte[] which was overwritten by my application because the code in C# stores the data in the DataTable column as System.Byte[] while updating the data I didn't decode it and update it .
I am using Navicat premium when I query data it shows me the result when I right click on the grid result and copy as insert statement it shows me two result for different rows
like this
INSERT INTO "public"."cards" ("ecode", "tpl") VALUES ('4210149888659', E'System.Byte[]');
INSERT INTO "public"."cards" ("ecode", "tpl") VALUES('3650257637661',E '\\247\\377\\001\\021\\340\\000\\230\\000\\002U\\000e\\000\\362\\000\\002-\\000\\253\\000p\\000\\002\\207\\000~\\000g\\000\\002\\215\\000{\\000\\317\\000\\002\\334\\000h\\000\\222\\000\\001|\\000\\004\\001U\\000\\002\\202\\000K\\000\\201\\000\\001\\000\\000\\204\\000\\241\\000\\001w\\000\\213\\000\\305\\000\\002\\021\\000V\\000\\237\\000\\002L\\001=\\001\\364\\000\\001X\\001"\\001\\313\\000\\002J\\000\\010\\001\\324\\000\\001\\370\\000\\037\\001J\\000\\002;\\0017\\000\\202\\000\\002\\300\\000\\317\\0007\\000\\002\\215\\000[\\000\\004\\011\\017\\007\\012\\005\\015\\014\\006\\016\\012\\007\\010\\005\\005\\007\\011\\010\\001\\004\\012\\017\\002\\003\\010\\012\\004\\010\\005\\003\\013\\014\\005\\017\\007\\003\\010\\003\\001\\011\\004\\012\\006\\020\\011\\005\\013\\015\\010\\002\\004\\005\\010\\007\\011\\012\\000\\002\\002\\020\\012\\003\\015\\000\\005\\002\\017\\003\\000\\006\\016\\020\\010\\017\\014\\000\\001\\012\\001\\010\\011\\002\\004\\007\\010\\000\\002\\006\\011\\007\\003\\020\\011\\003\\001\\005\\011\\000\\007\\002\\012\\002\\000\\020\\000\\016\\004\\017\\004\\003\\011\\017\\000\\003\\004\\000\\001\\007\\017\\002\\001\\017\\014\\006\\002\\016\\015\\011\\015\\006\\014\\016\\010\\020\\013\\000\\003\\006\\015\\002\\005\\020\\015\\016\\015\\004\\001\\003\\015\\010\\010\\006\\014\\002\\007\\020\\014\\011\\001\\000\\014\\010\\003\\016\\001\\015\\017\\020\\013\\006\\013\\016\\013\\011\\001\\014\\013\\004\\013\\002\\013\\001\\000'
);
You can't just convert it because PostgreSQL can't guarantee it can be converted safely. The best you can do is to convert the escaped form into a string and that's not what you probably want. Keep in mind that since bytea is binary data there is no way that PostgreSQL can be sure that the string that comes out will be legit. You could have embedded nulls in a UTF-8 string, for example, which could cause some fun with buffer overruns if you aren't careful.
This is the sort of thing that should be done in the client-side and you should assume that the data is binary, and not necessarily a valid string. If you want to store strings, store text fields, not bytea.