Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.


I have a simple Function on my database:

`CREATE OR REPLACE FUNCTION app_owner.mbdevu_return_payload_test(IN as_mbdevu_device_id VARCHAR(128))

RETURNS VARCHAR(32767) BEGIN RETURN 'Bill Aumen test'; END;`

When I execute Select mbdevu_return_payload_test('x') from ISQL, it works as expected.

I have created a Remote Server and Function: CREATE OR REPLACE FUNCTION "app_owner"."mbdevu_return_payload_test"( in "as_mbdevu_device_id" varchar(128) ) returns varchar(32767) at 'TIFISServer..app_owner.mbdevu_return_payload_test'

When I execute in ISQL from the remote database: SELECT app_owner.mbdevu_return_payload_test('x') I get an error -660 Count Field Incorrect

It all seems so simple, I must be missing something basic.

asked 21 Sep '16, 19:03

Bill%20Aumen's gravatar image

Bill Aumen
accept rate: 16%

The documentation is a little bit unclear about VARCHAR returns: Remote Procedure Calls.

LONG VARCHAR is explicitly stated as not being a valid return type, while CHAR is, but not a word about VARCHAR (without LONG). So possibly VARCHAR(32767) is interpreted as LONG VARCHAR, which would generate that error

So I suppose you'd be better off using a procedure with a result set instead of that function (but that's just my two cents) .

permanent link

answered 22 Sep '16, 04:24

Reimer%20Pods's gravatar image

Reimer Pods
accept rate: 11%

but not a word about VARCHAR

As SQL Anywhere usually treats CHARs as VARCHARs (and states that "CHAR is a domain, implemented as VARCHAR."), I would think that VARCHAR is valid, too.

There could also be a limitation to 255 characters, as several builtin functions treat longer strings differently.

In case VARCHAR(32767) is not valid for parameters and return values of RPCs, it may also be invalid as part of a RPC's result set.

That's my own guesswork, obviously.

(22 Sep '16, 08:16) Volker Barth

This is a bug in the software and is now corrected. The fix will appear in and or later versions. Thanks for reporting the problem.

permanent link

answered 27 Sep '16, 12:03

JBSchueler's gravatar image

accept rate: 19%

Thanks JB.

(27 Sep '16, 12:06) Bill Aumen
Comment Text Removed

Jack, so VARCHAR/NVARCHAR and CHAR/NCHAR will work as supported types then (up to their maximum of 32767 characters), or is there any length limitation?

(I'm asking as the docs are somewhat indifferent here, as Reimer has pointed out, and some client APIs seem to restrict regular VARCHARs to 32767 bytes, not characters, and describe longer data types as long varchar...)

(28 Sep '16, 02:59) Volker Barth

You do have to put up with the vagaries of ODBC. I tried to return an NVARCHAR(32767) result filled with the character Yee from the Deseret alphabet (2 surrogate pairs, or 4 bytes per character). The NVARCHAR string requires 4*32767 bytes of storage in the database. The character set used to transmit the data is UTF-8. On the local server side, I end up with an NVARCHAR result containing 16384 characters and a BYTE_LENGTH of 65535 (and no warning about the truncation). Now 65,535 is an odd number and when I looked at the last character in the string, it is garbage. This suggests that ODBC limited the result to a maximum 65,535 bytes.

Presumably, if all of your National Characters can be represented as single-byte UTF-8 then you don't have to worry.

(28 Sep '16, 09:48) JBSchueler
Replies hidden

Well, I have not yet had to cope with the Deseret alphabet (probably as I'm not aware when the latter days will begin), but of course I have to deal with German umlauts which do require 2 bytes with UTF-8...

So a big thanks for the clarification:)

(28 Sep '16, 10:04) Volker Barth

The Deseret alphabet consists entirely of emoji characters, thus making it far ahead of its time. Consider, for example, the glyph for the letter Gay...

(28 Sep '16, 16:27) Breck Carter

WOW! I am surprised at the lack of capability! Returning CHAR(255) still didn't work. But returning INT did.

So I guess I will make remote tables on the remote server, and run the actual function there.

permanent link

answered 22 Sep '16, 11:44

Bill%20Aumen's gravatar image

Bill Aumen
accept rate: 16%

You're the last person I would expect to be surprised, given your history with RPC oddities over the years.

Anyway, try CHAR ( 64 )... that's another magic number like 255 in The Funky World Of ODBC And Other Remote Oddities.

(22 Sep '16, 16:10) Breck Carter
Replies hidden

Another suggestion: Turn the RPC function into an RPC procedure that returns a singleton SELECT result set, then wrap the procedure call in a CREATE FUNCTION on the destination side if you really really really really really want a value-returning-function-thingie.

(22 Sep '16, 16:12) Breck Carter

We have created a SQLA web-server for an iPad project. The IT guys have isolated it via firewalls from the database server. I don't want to keep any actual data on the web server database.

I probably could never have succeed with the RPC anyway, as I would no doubt need a LONG VARCHAR to return the JSON payload I am creating.

So I have now created Remote Tables on the web server, and run the native SP on the web server instead of having it as an RPC. Problem solved and web service providing data as needed.

(22 Sep '16, 16:21) Bill Aumen

Looking into this since it doesn't seem right.

(22 Sep '16, 17:05) JBSchueler

Hi JB.

Just wondering if you found anything?

My current problem is solved, but we are just starting a few projects on this SQLA web server and will have many more uses for RPCs.

Thanks, Bill

(27 Sep '16, 12:01) Bill Aumen
Replies hidden

CREATE PROCEDURE with RESULT set is highly recommended, as it does not seem to have any of the data type restrictions affecting procedure OUT parameters or function RETURNS clauses. Foxhound makes heavy use of result-set-returning RPC procedures where SQL Anywhere is used on both sides. If you are dealing with Other Software on the remote side, your mileage may vary.

(28 Sep '16, 07:21) Breck Carter
showing 4 of 6 show all flat view
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 21 Sep '16, 19:03

question was seen: 2,928 times

last updated: 28 Sep '16, 16:27