on 2021 Dec 29 7:32 AM
Domains can be created in a SQL Anywhere database as a built-in data type. However there is a limitation that is not documented or maybe can be resolved.
We're using domains as a proper way to achieve the generation of jsons from the database.
Example: I create the following domains which are sub sets of tables:
create domain domain_Product row(Name varchar(64),Grade varchar(10),FlashPoint numeric(10,6)); create domain domain_OrdLine row(Products domain_Product,Quantity numeric(10,2),Price numeric(10,2)); create domain domain_Order row(Number varchar(16),Customer varchar(80),Status integer,Lines domain_OrdLine);I created 2 functions using a domain data type as a result set. One for fetching product properties
create or replace function GetProductRow(in in_ProductId integer) returns domain_Product begin declare row_Product domain_Product; // select row(Name,Grade,FlashPoint) into row_Product from Product where ProductId = in_ProductId; // return row_Product; endAnd one for fetching properties from OrderLines
create or replace function GetOrderLines(in in_OrderId integer) returns array of domain_OrdLine begin declare array_OrderLine array of domain_OrdLine; // select array_agg(row(GetProductRow(ProductId),Quantity,Price)) into variable array_OrderLine from OrderLines where OrderId = in_OrderId; // return array_OrderLine; end;So now I'm able to create a proper json for a given order with a variable declaration and a simple select statement:
create or replace variable row_Order domain_Order;So far so good. Now I want to add an additional property from the Product table to the json result set. For example Packaging. I would then extend the domain_Product with the new property and adjust the GetProductRow function to return this additional property. And I would expect the json to be extended with the new property at Product level with in the OrderLine object.select row(Number ,Customer ,Status ,GetOrderLines("Order".Id) ) from "Order" where OrderId = 1 for json raw
But the system will generate an Error because the domain_OrdLine and the domain_Order do not have the proper domain_Product definition. So the domain_OrdLine and the domain_Order need to be dropped and created again.
What happens is that a domain creation replaces the domain_Product with the definition of the domain_Product and will not save the domain data type itself as one would expect.
Similar as when a domain is created with product.name%type. If then the variable property in the product table is altered from 80 characters to 120 characters the domain variable is not extended. But that might be something you would expect that would happen.
These limitations are not in the documents. I would like to see it resolved but I guess that won't be possible due to the setup of the domains currently in the database.
User | Count |
---|---|
67 | |
11 | |
10 | |
10 | |
9 | |
8 | |
6 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.