1. william yau
  2. PowerBuilder
  3. Wednesday, 12 January 2022 06:21 AM UTC

hi 

 my sql server value(x) datatype  is nvarchar. 

i use following sql statement can store chinese values on x 

update table set x = N'chinese character' 

my question how to use this sytanx on 

datawindow.update()

 

William

 

Sivaprakash BKR Accepted Answer Pending Moderation
  1. Wednesday, 12 January 2022 14:10 PM UTC
  2. PowerBuilder
  3. # 1

Hello William,

Hope you are using SQL SERVER (Not MySQL).

To store UNICODE characters in SQL Server database
1.  Declare the field data type as nvarchar (or its equivalent)
2.  See that the datawindow could accept UNICODE characters in that particular field.
3.  In the SQLPREVIEW event of that particular datawindow, write the following code

/* Need to write a global replace function to replace the corresponding values with the new values */

Choose case sqltype
       Case PreviewInsert!
            sqlsyntax = of_globalreplace(sqlsyntax,"( '", "( N'", true)
            sqlsyntax = of_globalreplace(sqlsyntax ,", '", ",N'", true)
            this.setsqlpreview(sqlsyntax)

       Case PreviewUpdate!, PreviewDelete!
            sqlsyntax = of_globalreplace(sqlsyntax ,"= '","= N'", true)
            this.setsqlpreview(sqlsyntax)
End Choose

The global function

Function of_globalreplace (as_source, as_old, as_new, ab_ignorecase)
/*
PassBy           Argument Type        Argument Name
value            string               as_source
value            string               as_old
value            string               as_new
value            boolean              ab_ignorecase 
*/
Long   ll_Start, ll_OldLen, ll_NewLen
String ls_Source

//Check parameters
If IsNull ( as_source )  or IsNull ( as_old )  or IsNull ( as_new )  or IsNull ( ab_ignorecase )  Then
   string ls_null
   SetNull ( ls_null )
   Return ls_null
End If

//Get the string lenghts
ll_OldLen = Len ( as_Old )
ll_NewLen = Len ( as_New )

//Should function respect case.
If ab_ignorecase Then
   as_old = Lower ( as_old )
   ls_source = Lower ( as_source )
Else
   ls_source = as_source
End If

//Search for the first occurrence of as_Old
ll_Start = Pos ( ls_Source, as_Old )

Do While ll_Start > 0
   // replace as_Old with as_New
   as_Source = Replace ( as_Source, ll_Start, ll_OldLen, as_New )

   //Should function respect case.
   If ab_ignorecase Then
      ls_source = Lower ( as_source )
   Else
      ls_source = as_source
   End If

   // find the next occurrence of as_Old
   ll_Start = Pos ( ls_Source, as_Old,  ( ll_Start + ll_NewLen )  )
Loop

Return as_Source

4.  Now do the normal datawindow update.   (eg. dw_1.Update() or dw_1.Update(True, False) ... )

HTH

Happiness Always
BKR Sivaprakash

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.