Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not insert emoji? #260

Closed
uonun opened this issue Oct 26, 2022 · 2 comments
Closed

can not insert emoji? #260

uonun opened this issue Oct 26, 2022 · 2 comments

Comments

@uonun
Copy link
Contributor

uonun commented Oct 26, 2022

what can i do to get the original string with emoji rather than \uxxx?

tested:

  1. if i insert with other program which is implemented in dotnet core, then Query by go_ora, it works well. so i think the problem is the insert stmt.
  2. INSERT value as go_ora.NClob, got: ORA-01461: can bind a LONG value only for insert into a LONG column

pls help, thanks.

here is the source code:

CREATE TABLE TABLENAME
(
	ID	NUMBER NOT NULL,
	CONTENT NCLOB,
	-- OTHERS
)
	CONN := "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=****)(PORT=****))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=***)))"
	urlOptions := map[string]string{
		"trace file":         "trace.log",
	}
	dsn := go_ora.BuildJDBC("***", "***", CONN, urlOptions)
	conn, err := sql.Open("oracle", dsn)
	// check for error
	defer conn.Close()

	stmt, err := conn.Prepare("INSERT INTO TABLENAME (ID,CONTENT) VALUES (TABLENAME_s.nextval,:1) RETURNING ID INTO :2")
	// check for error
	defer stmt.Close()

	value := "😁🍎$➔®≧①◎◉§❤️🇨🇳"
	var newid int64


	_, err = stmt.Exec(value, "test", &newid)

	rows, err := conn.Query("SELECT CONTENT FROM TABLENAME WHERE ID = :1", newid)
	defer rows.Close()
	var newValue string
	for rows.Next() {
		err = rows.Scan(&newValue)
		fmt.Print(err)
	}

	fmt.Println(value)	// 😁🍎$➔®≧①◎◉§❤️🇨🇳
	fmt.Println(newValue)	// \ue466\ue466$\ue466≧①◎\ue40a忑\ue466\ue466
stmt.connection.tcpNego

MessageCode:
1 = 0x1
ProtocolServerVersion:
6 = 0x6
ProtocolServerString:
"x86_64/Linux 2.4.xx"
OracleVersion:
8100
ServerCharset:
852
ServerFlags:
3 = 0x3
CharsetElem:
6
ServernCharset:
2000

DB:

VAR VALUR
NLS_CALENDAR GREGORIAN
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_CURRENCY $
NLS_DATE_FORMAT DD-MON-RR
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_DUAL_CURRENCY $
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
PARAMETER VALUE
NLS_CHARACTERSET ZHS16GBK
NLS_NCHAR_CHARACTERSET AL16UTF16
@sijms
Copy link
Owner

sijms commented Nov 15, 2022

sorry for late replay
the problem fixed in new release
you need use one of the following approach for insert

1- casting string to go_ora.NVarChar

value := "😁🍎$➔®≧①◎◉§❤️🇨🇳"
_, err = conn.Exec(fmt.Sprintf(`INSERT INTO %s(ID, CONTENT) VALUES(1, :1)`, tableName), go_ora.NVarChar(value))
if err != nil {
    fmt.Println("Can't insert: ", err)
    return
}

2- use go_ora.NClob

value := "😁🍎$➔®≧①◎◉§❤️🇨🇳"
_, err = conn.Exec(fmt.Sprintf(`INSERT INTO %s(ID, CONTENT) VALUES(1, :1)`, tableName), go_ora.NClob{String: value})
if err != nil {
    fmt.Println("Can't insert: ", err)
    return
}

uonun pushed a commit to uonun/gorm-oracle that referenced this issue Nov 16, 2022
uonun pushed a commit to uonun/gorm-oracle that referenced this issue Nov 16, 2022
@uonun
Copy link
Contributor Author

uonun commented Nov 17, 2022

Thank you very much, it is ok now. @sijms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants