How to document a nullable union type with jsDoc? - jsdoc3

According to jsDoc - tag #type the correct way to annotate a union type is #type {(number|boolean)} and the correct way to annotate a nullable type is #type {?number}.
How do I document a type which is a union and nullable at the same time? I tried
#type {?(number|boolean)} -- question mark in front of parentheses
#type {(?number|?boolean)} -- mark every type of the union individually nullable
#type {(?number|boolean)} -- mark only the first type of the union nullable
However, my IDE (JetBrains PhpStorm) compains about every variant.

Related

I want to change the type of DB table field from number to text type I should use

I want to change the type of db table from number to text type I should use _ operator
you can use
declare #a as int = 25
select cast (#a as nvarchar (255)) as example
for more details, you can read this - https://learn.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?f1url=%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(CONVERT_TSQL);k(sql13.swb.tsqlresults.f1);k(sql13.swb.tsqlquery.f1);k(MiscellaneousFilesProject);k(DevLang-TSQL)%26rd%3Dtrue&view=sql-server-ver15

Not able to update column which was set as null using 'select into' statement in sybase

I am creating a temp table in sybase like below
select col1 = null, col2 =2 into #myTable
Here when I try to update col1
update #myTable set col1 = 'test'
I get error - "[Error Code: 257, SQL State: 42000] Implicit conversion from datatype 'VARCHAR' to 'INT' is not allowed. Use the CONVERT function to run this query."
Can anyone please help me fix it?
Assuming this is Sybase ASE (257 is a standard ASE system error number) ...
col1=null doesn't tell the database what the datatype of col1 should be so the database defaults the column's datatype to int.
When creating a table via select/into you need to insure each column is created with the desired datatype. For this particular instance try:
select col1=convert(varchar(10),null), col2=convert(tinyint,2) into #myTable
NOTES:
modify the convert() calls to reference the desired datatypes
when the new column is populated from another table's column(s) the source column(s) datatypes will be used in determing the datatype of the new column
Also keep in mind the following:
select col1='test' into #otherTable
The datatype for col1 will be determined from the initial data value; in this case the value 'test' tells the database you need to store 4 characters so the database will default the column's datatype to varchar(4). This should be fine as long as you never intend to insert anything longer than varchar(4) otherwise you'll need to provide a convert() with the initial select/into to explicitly state the column's datatype, eg:
select col1=convert(varchar(35),'test') into #otherTable
Assuming you get past the Implicit conversion from datatype 'VARCHAR' to 'INT' is not allowed. error message your next bump-in-the road may occur if you try something like:
update #myTable set col2 = NULL
With the result being that you're presented with an error message similar to column does not allow nulls.
As with datatype determination, Sybase (ASE) will try to determine a column's NULLability in a few different ways:
if column is assigned a 'value' of NULL (as in the example: col1 = null) then ASE will configure the column to allow NULLs
if the column's value is being copied from another table then the source column's NULLability will be used in determining the new column's NULLability
if the query explicitly defines the column as NULLable (see example - below) then the column will be configured to allow NULLs
if the database option allow nulls by default is false (ASE default setting) then the column's NULLability will be set to 'not NULL'
when all else fails ...
if the database option allow nulls by default is true then the column's NULLability will be set to 'NULL'(able)
An example of explicitly defining the column to allow NULLs:
select col1 = convert(varchar(35) null,'test') into #otherTable

Unpredictable behaviour in nested CASE statement

I'm unable to figure out why the control goes always to a statement irrespective of inside CASE condition.
A normal SQL statement works, but with my table it does not work.
--Not working--
SELECT
CASE WHEN [INTERNALDESCRIPTION] IS NOT NULL THEN --INTERNALDESCRIPTION IS A TEXT FIELD
CASE WHEN 'INT' = 'INT' THEN -- Or 'TEXT' = 'INT'
REPLACE( CONVERT(VARCHAR(MAX),[INTERNALDESCRIPTION] ) ,'''','') --should have come here
ELSE
REPLACE( CONVERT(INT,[INTERNALDESCRIPTION] ) ,'''','' ) -- Always comes here no matter what condition
END
ELSE
'NULL'
END
FROM DBO.RESOURCESTRINGMASTER WITH(NOLOCK) WHERE 1=1
-------working--
DECLARE #VALUE1 AS varchar(max) = '1Test', #VALUE2 AS VARCHAR(MAX) = '2'
SELECT
CASE WHEN #VALUE1 IS NOT NULL THEN
CASE WHEN 'INT' = 'INT' THEN
REPLACE( CONVERT(VARCHAR(MAX),#VALUE1 ) ,'''','')
ELSE
REPLACE( CONVERT(INT,#VALUE2 ) ,'''','' )
END
ELSE
'NULL'
END
And results in below error:
Explicit conversion from data type text to int is not allowed.
Explicit conversion from data type text to int is not allowed.
This error message seems pretty clear. Why are you using a text data type? It is deprecated. To quote from the documentation:
IMPORTANT! ntext, text, and image data types will be removed in a future version of SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.
So, your code on the real table is executing the ELSE condition, which causes it to fail. In the code with constants, ELSE condition is not failing. Why is this?
I think the error is being caught in the compilation phase of the query. The error does not occur in the second example, because SQL Server is short-circuiting the query, recognizing that the ELSE is not needed. The code in the second example is simply not compiled.
I am pretty sure you would see the same behavior if you replaced the code with 1 / 0 (although the other part of the case expression would need to change as well for the types to be compatible).
It is not running the statement, it is failing because it sees something illegal.
If you want to see it on the other case change this line
DECLARE #VALUE1 AS varchar(max) = '1Test', #VALUE2 AS VARCHAR(MAX) = '2'
to
DECLARE #VALUE1 AS TEXT = '1Test', #VALUE2 AS VARCHAR(MAX) = '2'
You are comparing different test cases -- the first is not using VARCHAR

How to pass single-column table to AMDP method?

I need to pass a table with a single column to an AMDP method which throws the error, the other parameters go fine:
TYPES: BEGIN OF s_so_i,
parent_key TYPE snwd_so_i-parent_key,
product_guid TYPE snwd_pd-node_key,
node_key TYPE snwd_so_i-node_key,
END OF s_so_i.
TYPES: BEGIN OF s_product,
product_guid TYPE snwd_pd-node_key,
category TYPE snwd_pd-category,
END OF s_product.
TYPES: tt_product TYPE STANDARD TABLE OF s_product,
tt_so TYPE STANDARD TABLE OF snwd_node_key, "<-- error
tt_so_i TYPE STANDARD TABLE OF s_so_i.
How should I define it?
instead of using snwd_node_key I can suggest you to use EGUID_S.
EGUID_S is a structure with only including a single column with RAW16 as SYSUUID
instead of
tt_so TYPE STANDARD TABLE OF snwd_node_key,
use
tt_so TYPE STANDARD TABLE OF EGUID_S,
Adding this solved the problem:
TYPES: BEGIN OF s_so,
so_guid TYPE snwd_so-node_key,
END OF s_so.
TYPES: tt_product TYPE STANDARD TABLE OF s_product,
tt_so_i TYPE STANDARD TABLE OF s_so_i,
tt_so TYPE STANDARD TABLE OF s_so. <--
So it seems the table type must point to a structure type.

XML Query with a variable in WHERE

I have this code that works well. But I want to have a variable to change its value in run time. I want the output xml file in C#.
declare #MySearch nvarchar(50)
set #MySearch='بودان'
SELECT ID, Family
FROM Table_1
where freetext(Family, #MySearch, LANGUAGE 1025)
FOR XML RAW ('Employee'), ROOT ('Employees'), ELEMENTS XSINIL;
EDITED:
I ran this code and got this error:
Null or empty full-text predicate.
I want the output xml file in C#.
declare #MySearch nvarchar(50)
--set #MySearch=N'بودان'
SELECT ID, Family
FROM Table_1
where freetext(Family, #MySearch, LANGUAGE 1025)
FOR XML RAW ('Employee'), ROOT ('Employees'), ELEMENTS XSINIL;
The "N" makes the difference, and you need it twice...
Try this:
DECLARE #v1 VARCHAR(10)='بودان';
DECLARE #v2 VARCHAR(10)=N'بودان';
DECLARE #nv1 NVARCHAR(10)='بودان';
DECLARE #nv2 NVARCHAR(10)=N'بودان';
SELECT #v1,#v2,#nv1,#nv2;
The result
????? ????? ????? بودان
Only the very last attempt will show what you need...
The reason: A normal string SET #v='MyString' is not handled as UNICODE
It is neither enough to declare the variable as NVARCHAR nor is it enough to store a unicode literal like N'SomeText'.
EDIT:
After long disucussion in comments the final sentence to solve the issue was this:
Of course you must be connected with the DB to do this!
What ever you want to with your database, first you need an opened connection.