Jump to content
php.lv forumi

MSSQL CAST probléma


SkyBreak*

Recommended Posts

Sveiki, saksāros ar MSSQL vienu problēmu..

 

Mazliet par sitāciju.

 

Lietoju codeigniter mssql db klasi. Datubāzē field type ir ntext. Pēc parasta SELECT no datubāzes izmetās erros - "Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library" .

 

Pēc tam lasīju internetā, ka vajag ntext tipu uz text datubāzē pārmainīt. Izdarīju tā, bet tad atkal nākamā problēma, jo man datubāzē visi ieraksti ir cyrillic'ā .. Pēc tipa nomainīšanas visi ieraksti palika - ???? .

 

Meklēju talāk risinājumu, atradu funkciju CAST..

 

Mans querys izskatās šādi:

SELECT question_id, id, question_right_answer, CAST(question_text AS text) as question_text, CAST(question_answer_1 AS text) as question_answer_1, CAST(question_answer_2 AS text) as question_answer_2, CAST(question_answer_3 AS text) as question_answer_3, CAST(question_answer_4 AS text) as question_answer_4 FROM [exam].[dbo].[questions_russian] WHERE question_id = 1149

 

Lai nerastos jautājumi kapēc man tāda datubāze, tapēc, ka codeigniter MSSQL klase mazliet čakarejas, tapēc rakstu pilnu nosaukumu ar visiem escape tagiem..

 

Izmet erroru - "Must specify table to select from.

 

SELECT *"

 

Biju arī mēģinājis savādāku allias likt - CAST(question_answer_4 AS text) as question_answer_4_alias, bet vienalga, tas pats.

 

Problēma man diezgan steidzama, tapēc ļoti ceru, ka kādam ir kāda ideja, kā to novērst, paldies...

Link to comment
Share on other sites

Ar pilku mssql funkciju

 

$query = "SELECT question_id, id, question_right_answer, CAST(question_text AS text) as question_text, CAST(question_answer_1 AS text) as question_answer_1, CAST(question_answer_2 AS text) as question_answer_2, CAST(question_answer_3 AS text) as question_answer_3, CAST(question_answer_4 AS text) as question_answer_4 FROM questions_russian WHERE question_id = 1149";
$result = mssql_query($query);

$row = mssql_fetch_array( $result );

print_r($row);

 

Rezultāts:

 

Array ( [0] => 1149 [question_id] => 1149 [1] => 1027.0 [id] => 1027.0 [2] => 2 [question_right_answer] => 2 [3] => ??????????? ?? ??? ???????? ???????? ?????? ??? ??????????? ???????? ?????? ?????????? ????????? ???????? ?? ???????? ??????, ???????????? ?? ???????? [question_text] => ??????????? ?? ??? ???????? ???????? ?????? ??? ??????????? ???????? ?????? ?????????? ????????? ???????? ?? ???????? ??????, ???????????? ?? ???????? [4] => ???????????. [question_answer_1] => ???????????. [5] => ???????????. [question_answer_2] => ???????????. [6] => [question_answer_3] => [7] => [question_answer_4] => )

 

Pameiģināju kādu no field'iem bez CAST funkcijas, tad parāda to pašu, bet ar erroru.

 

WARNING! Some character(s) could not be converted into client's character set. Unconverted bytes were changed to question marks ('?'). (severity 16) in

 

EDITED:

 

Pievienoju augšā.. - > ini_set('mssql.charset', 'UTF-8');

 

 

[question_right_answer] => 2 [3] => РазрешаетÑÑ Ð»Ð¸ Вам подавать звуковой Ñигнал Ð´Ð»Ñ Ð¿Ñ€Ð¸Ð²Ð»ÐµÑ‡ÐµÐ½Ð¸Ñ Ð²Ð½Ð¸Ð¼Ð°Ð½Ð¸Ñ Ð´Ñ€ÑƒÐ³Ð¸Ñ… учаÑтников дорожного Ð´Ð²Ð¸Ð¶ÐµÐ½Ð¸Ñ Ð·Ð° дорожным знаком, изображенным на риÑунке? [question_text]

 

Ir idejas, kā varētu dabūt ko lasāmāku :) ?

Edited by SkyBreak*
Link to comment
Share on other sites

Iespējams ka cast() tur nav pie vainas, bet kaut kas ar collation ir saplīsis/nesakrīt.

Vispirms paskaties kādi ir pieejami

SELECT * FROM fn_helpcollations();

Pēc tam pamēģini kādu no viņiem, kas izklausās derīgs

SELECT question_text COLLATE <te kāds no fn_helpcollations().name> FROM ...

Edited by v3rb0
Link to comment
Share on other sites

Parāda tikai

Array ( [0] => Albanian_BIN [name] => Albanian_BIN [1] => Albanian, binary sort [description] => Albanian, binary sort ) 

Izmet tikai kkādu Albian :) neizklausās, ka derētu, mssql db taisīts uz Latvian_CI_AI.

 

Problēmas ir mssql serverī ?

Edited by SkyBreak*
Link to comment
Share on other sites

Tas esmu es, topika autors, viekārši tagad savs profils, jo iepriekš reCHAPTA negaja (:

 

ini_set('mssql.charset', 'UTF-8');
mssql_connect("****", "****", "****") or die(mssql_error());
mssql_select_db("*****") or die(mssql_error());


$query = "SELECT question_text COLLATE Cyrillic_General_CI_AI FROM questions_russian WHERE question_id = 1149";

$result = mssql_query($query);

$row = mssql_fetch_array( $result );

print_r($row);

 

Mēģinājums vairākus cyrllic collate's mainīt, vispār, bez izmaiņam!

 

 

Pagaidām ir sitācija tāda, ka mājaslapu taisu uz Linux Gentoo, Apaches, bet mājaslapas pasūtītājām stāvēs uz IIS,, Varbūt ir iespēja, ka tur viss strādās kā vaig :) ?

Edited by roleeks
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...