Please be aware that the SAP SQL Anywhere Forum will be shut down on August 29th, 2024 when all it's content will be migrated to the SAP Community.

Question 1: Is the EXTERNAL NAME clause with no LANGUAGE attribute bound at compile time (when the CREATE PROCEDURE is executed) or is it bound at run time (when the procedure is called or the DLL is loaded)?

The answer appears to be "run time" although that doesn't seem to be mentioned in the Help.

Question 2: Is it possible to specify separate DLL names for Windows 32-bit and Windows 64-bit in the same EXTERNAL NAME clause?

E.g., CREATE PROCEDURE mystring( IN instr LONG VARCHAR ) EXTERNAL NAME 'Win32:mystring@mylib32.dll;Win64:mystring@mylib64.dll';

I am trying to make a database easily portable between the two platforms, by simply providing both DLLs and letting SQL code pick which one it wants at runtime.

Here is an excerpt from the Help: CREATE PROCEDURE statement External call



A procedure using the EXTERNAL NAME clause with no LANGUAGE attribute defines an interface to a native function written in a programming language such as C. The native function is loaded by the database server into its address space.

The library name can include the file extension, which is typically .dll on Windows and .so on Unix. In the absence of the extension, the software appends the platform-specific default file extension for libraries. The following is a formal example.

CREATE PROCEDURE mystring( IN instr LONG VARCHAR ) EXTERNAL NAME 'mystring@mylib.dll;';

A simpler way to write the above EXTERNAL NAME clause, using platform-specific defaults, is as follows:

CREATE PROCEDURE mystring( IN instr LONG VARCHAR ) EXTERNAL NAME 'mystring@mylib';

When called, the library containing the function is loaded into the address space of the database server. The native function will execute as part of the server. In this case, if the function causes a fault, then the database server will be terminated. Because of this, loading and executing functions in an external environment using the LANGUAGE attribute is recommended. If a function causes a fault in an external environment, the database server will continue to run.

For syntaxes that support operating-system, if you do not specify operating-system, then it is assumed that the procedure runs on all platforms. If you specify Unix for one of the calls, then it is assumed that the other call is for Windows.


asked 18 Dec '12, 08:38

Breck%20Carter's gravatar image

Breck Carter
accept rate: 20%

edited 18 Dec '12, 08:41

1) You are correct, it is at run time once the dll is loaded.

2) No, there currently is no way to specify both a 32-bit and 64-bit dll in the same external name clause. Your best bet is to have two external functions (one for 32-bit and one for 64-bit) and then have an extra SQL stored function that determines the appropriate bitness and calls the correct external function.

permanent link

answered 18 Dec '12, 09:30

Karim%20Khamis's gravatar image

Karim Khamis
accept rate: 40%

Re #2: sounds like an enhancement is required! - I've added it to the list.

(18 Dec '12, 10:32) Mark Culp

Based on Karim's answer, a simple workaround would be to

  • use a DatabaseStart event
  • and in that, use property('ProcessorArchitecture') to distinguish 32-bit and 64-bit servers (based on the return values "X86" or "X86_64"),
  • and then use ALTER PROCEDURE mystring to link to the desired bitness-specific DLL name, if necessary.

That way, you shound not need to change/wrap the external procedure calls within your code.

permanent link

answered 19 Dec '12, 03:17

Volker%20Barth's gravatar image

Volker Barth
accept rate: 34%

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: 18 Dec '12, 08:38

question was seen: 2,168 times

last updated: 19 Dec '12, 03:17