forsqlcreatej, forsqlinsertj, forsqlscriptj

NoteThe functions in this section are Java-based, and you must install them in your server before you can use them. For instructions, see Appendix E, “The Java-Based XQL Processor.”.

The Java-based forsql functions map SQLX-XML schema and SQLX-XML result set documents to a SQL script.

Syntax

sqlx_to_sql_script_function ::=
      forsqlcreatej(sqlx_schema, option_string)
      | forsqlinsertj(sqlx_resultset, option_string)
      |forsqlscriptj(sqlx_schema, sqlx_resultset, option_string)
 sqlx_schema::=basic_string_expression
 sqlx_resultset::=basic_string_expression
 option_string::=basic_string_expression

Description

Options

The general format of the option_string is described in “option_strings: general format”.

The forsqlcreatej, forsqlinsertj, and forsqlscripj functions support the following option, described in the “Exceptions” section, below.

xmlerror={exception | null | message}

Exceptions

If the value of sqlx_schema or sqlx_resultset is not valid XML:

Examples

The forsqlcreatej function:

set stringsize 16384
declare @schema varchar(16384) 
select @schema = forxmlschemaj(  
   "select pub_id, pub_name from pubs2.dbo.publishers",
   "tablename=extract  null=attribute") 
select forsqlcreatej(@schema, "") 
go
CREATE TABLE "extract"(      
   "pub_id" CHAR(4) null,       
   "pub_name" VARCHAR(40) null ) 

The forsqlinsertj function:

set stringsize 16384 
declare @rs varchar(16384) 
select @rs = forxmlj(   
   "select pub_id, pub_name from pubs2.dbo.publishers")
select forsqlinsertj(@rs, "")
go

   --Begin table "resultset"
insert into "resultset"   
   ("pub_id", "pub_name")    
    values ( '0736', 'New Age Books') 
insert into "resultset"   
   ("pub_id", "pub_name")    
    values ( '0877', 'Binnet & Hardley') 
insert into "resultset"   
   ("pub_id", "pub_name")    
    values ( '1389', 'Algodata Infosystems') 
--End table "resultset" 

The forsqlscriptj function:

set stringsize 16384
declare @rs varchar(16384)
declare @schema varchar(16384)
declare @dtd varchar(16384)
execute forxmlallj   
   "select pub_id, pub_name from pubs2.dbo.publishers",
   "tablename=extract  null=attribute",     
    @rs out, @schema out, @dtd out
declare @script varchar(16384)

select @script = forsqlscriptj(@schema, @rs, "") 
select @script
execute ("set quoted_identifier on " + @script )
execute ("select pub_id, pub_name from extract")
execute ("drop table extract")
go
(return status = 0)

Return parameters:

*****Values of @rs, @schema, and @dtd omitted********
(1 row affected)
(1 row affected) 

CREATE TABLE "extract"(      
   "pub_id" CHAR(4) null,      
    "pub_name" VARCHAR(40) null)

--Begin table "extract"
insert into "extract"   
   ("pub_id", "pub_name")    
    values ( '0736', 'New Age Books') 
insert into "extract"   
   ("pub_id", "pub_name")    
    values ( '0877', 'Binnet & Hardley') 
insert into "extract"   
   ("pub_id", "pub_name")    
    values ( '1389', 'Algodata Infosystems') 
--End table "extract" 

(1 row affected)
(1 row affected)
(1 row affected)
(1 row affected) 

pub_id pub_name
------ -------------------
1)	New Age Books                            
2)	Binnet & Hardley                         
3)	Algodata Infosystems                     

(3 rows affected)