I'm trying to create a service with an inner join query but it returns this error:
org.postgresql.util.PSQLException: A result was returned when none was expected.
This is my service:
<data name="consultarPersona" transports="http https local">
<config enableOData="true" id="mi_datasource">
<property name="carbon_datasource_name">fuente_datos</property>
</config>
<query id="contactos_registrados" useConfig="mi_datasource">
<sql>select * from t_contacto inner join t_datos_contacto on t_contacto.id = t_datos_contacto.id</sql>
</query>
<operation name="obtenerDatosContactos">
<call-query href="contactos_registrados"/>
</operation>
</data>
You should specify which columns do you want to return and generate the response, the result is an service like this:
<data name="consultarPersona" transports="http https local">
<config enableOData="true" id="mi_datasource">
<property name="carbon_datasource_name">fuente_datos</property>
</config>
<query id="contactos_registrados" useConfig="mi_datasource">
<sql>select name, age from t_contacto inner join t_datos_contacto on t_contacto.id = t_datos_contacto.id</sql>
<result element="contactoCollection" rowName="contacto">
<element column="name" name="name" xsdType="xs:string"/>
<element column="age" name="age" xsdType="xs:string"/>
</result>
</query>
<operation name="obtenerDatosContactos">
<call-query href="contactos_registrados"/>
</operation>
</data>
I hope this coudl help you.
Related
I don't know how to create a validator for 2 variables:
Q1. An user code that needs to be checked if exists prior to running the SQL query. I have an endpoint to check if the user code exists or not, how do I make it into a validator?
Q2. An array of dates, the best I could do was to use a pattern validator. I know there's also the possibility to set a parameter with paramType="array" and sqlType="date", but how can I configure this in the query parameters of the resource?
Please check the Data Service definition below:
<data name="APIDataService" serviceNamespace="" serviceGroup="" transports="http https local">
<description />
<config id="postgresDataService">
<property name="carbon_datasource_name">APIPostgres</property>
</config>
<!-- TODO: Q1. Here is the resource I want to use to validate the user code -->
<query id="validateUserCode" useConfig="postgresDataService">
<sql>
SELECT ( EXISTS ( SELECT 1
FROM user
WHERE code ILIKE :user_code ) )::INT AS does_user_exist
</sql>
<param name="user_code" sqlType="string" />
<result element="result">
<element column="does_user_exist" name="doesUserExist" xsdType="integer" />
</result>
</query>
<resource method="GET" path="validateUserCode">
<call-query href="validateUserCode">
<with-param name="user_code" query-param="user_code" />
</call-query>
</resource>
<query id="apiReportUserTotalEventsByDay" useConfig="postgresDataService">
<sql>
SELECT
calendar_date,
record_date,
user_code,
event_type_id,
event_count
FROM user_event
WHERE 1=1
AND calendar_date BETWEEN :calendar_date_start AND :calendar_date_end
AND record_date = ANY( ('{'||:record_date_array||'}')::DATE[] )
AND user_code = :user_code
</sql>
<!-- TODO: Q1. Here is the user code I want to validate -->
<param name="user_code" paramType="scalar" sqlType="string" />
<param name="calendar_date_start" paramType="scalar" sqlType="date" />
<param name="calendar_date_end" paramType="scalar" sqlType="date" />
<!-- TODO: Q2. Here is the array of date that I want to know
how I could convert into an paramType="array" sqlType="date" -->
<param name="record_date_array" paramType="scalar" sqlType="string" >
<validatePattern pattern="\s*\d{4}-\d{2}-\d{2}\s*(,\s*\d{4}-\d{2}-\d{2}\s*)*" />
</param>
<result element="result">
<element column="calendar_date" name="calendar_date" xsdType="string" />
<element column="record_date" name="record_date" xsdType="string" />
<element column="user_code" name="user_code" xsdType="string" />
<element column="event_type_id" name="event_type_id" xsdType="integer" />
<element column="event_count" name="event_count" xsdType="integer" />
</result>
</query>
<resource method="GET" path="apiReportUserTotalEventsByDay">
<call-query href="apiReportUserTotalEventsByDay">
<with-param name="user_code" query-param="user_code" />
<with-param name="calendar_date_start" query-param="calendar_date_start" />
<with-param name="calendar_date_end" query-param="calendar_date_end" />
<with-param name="record_date_array" query-param="record_date_array" />
</call-query>
</resource>
</data>
I followed following sample with one different i used MS SQL database.
http://wso2.com/library/tutorials/2013/11/scheduled-database-polling-with-wso2-data-services-server/
I am observing that polling is working as expected but timestamp (datetime column in sql is not getting updated)
Here is my DSS XML
<data enableBatchRequests="true" name="PollingService" serviceNamespace="http://ws.wso2.org/dataservice/samples/eventing_sample" transports="http https local">
<config enableOData="false" id="Default">
<property name="driverClassName">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="url">jdbc:sqlserver://geoshieldsp3\sqlexpress;databaseName=RahulTest</property>
<property name="username">sa</property>
<property name="password">CSSL#2014</property>
</config>
<query id="pollingQuery" output-event-trigger="pollingTrigger" useConfig="Default">
<sql>select x.[Call Number], x.Priority, x.Call_Type, x.DispatchDate,y.total from CADFeeds as x left join
(select *,count([Call Number]) over() as total from CADFeeds ) as y on x.[Call Number]=y.[Call Number]
where x.DispatchDate > (select TIMESTAMP from Timestamp where id=1)</sql>
<result element="Calls" rowName="call">
<element column="Call Number" name="CallNumber" xsdType="string"/>
<element column="Priority" name="Priority" xsdType="float"/>
<element column="Call_Type" name="Call_Type" xsdType="string"/>
<element column="DispatchDate" name="DispatchDate" xsdType="string"/>
<element column="total" name="count" xsdType="integer"/>
</result>
</query>
<query id="UpdateTimeStamp" useConfig="Default">
<sql>update dbo.Timestamp set timestamp = GETDATE() where ID=1</sql>
<param name="timestamp" ordinal="2" sqlType="STRING"/>
</query>
<event-trigger id="pollingTrigger">
<expression>//*[local-name()='count' and namespace-uri()='http://ws.wso2.org/dataservice/samples/eventing_sample']>0</expression>
<target-topic>polling_Topic</target-topic>
<subscriptions>
<subscription>http://localhost:8280/services/PollingProxy</subscription>
</subscriptions>
</event-trigger>
<operation name="PollingOperation">
<call-query href="pollingQuery"/>
</operation>
<operation name="UpdateTimeStamp">
<call-query href="UpdateTimeStamp">
<with-param name="timestamp" query-param="timestamp"/>
</call-query>
</operation>
</data>
Here is the DB schema for timestamp table
CREATE TABLE [dbo].[Timestamp](
[ID] [int] NULL,
[timestamp] [datetime] NULL
) ON [PRIMARY]
I do not see anything in the log or command prompt related to timestamp update.
Any help is greatly appreciated.
Thanks,
Rahul
There seems to be a mismatch between the operation and the query.
For the below SQL, query param is not needed as there are no arguments supplied.
Please try the following.
<operation name="UpdateTimeStamp">
<call-query href="UpdateTimeStamp">
</call-query>
</operation>
<query id="UpdateTimeStamp" useConfig="Default">
<sql>update dbo.Timestamp set timestamp = GETDATE() where ID=1</sql>
</query>
I have created a simple dss service which by inputing cust_id it gives me the customer data.
I have exposed this webservice as http get resource with the following url
GET /services/getCustDetailDSS/getDetail?cid=101
Corrsponding xml code for my service is as follows
<data name="getCustomerDetailDSS" serviceGroup="" serviceNamespace="">
<description/>
<config id="mydb">
<property name="carbon_datasource_name">mydb</property>
</config>
<query id="get_customer_detail" useConfig="mydb">
<sql>select identifier,user_status from customer_detail where identifier = :cid</sql>
<param name="cid" paramType="SCALAR" sqlType="STRING"/>
<result element="customer">
<element column="identifier" name="cid" xsdType="xs:string"/>
<element column="user_status" name="status" xsdType="xs:string"/>
</result>
</query>
<operation name="get_customer_detail_operation">
<call-query href="get_customer_detail">
<with-param name="cid" query-param="identifier"/>
</call-query>
</operation>
<resource method="GET" path="/getDetail">
<call-query href="get_customer_detail">
<with-param name="cid" query-param="cid"/>
</call-query>
</resource>
</data>
But now i want the dss service to read cust_id from url instead of passing it as a parameter.
i.e i want to hit dss service as
GET /services/getCustDetailDSS/cid/101/getDetail
How can i do this in DSS ?
Can anyone provide wat changes i need to do in my dss?
For GET /services/getCustDetailDSS/getDetail/cid/101
You have to edit your resource path as follows.
<resource method="GET" path="getDetail/cid/{cid}">
With WSO2 DSS 3.2.1, you can now define your query string parameter as below:
<param name="cid" sqlType="QUERY_STRING"/>
instead of:
<param name="cid" paramType="SCALAR" sqlType="STRING"/>
and your URL should look like:
.../getDetail?cid=101
I'm new to WSO2 Data Services Server and I trying to figure out how to get complex element types working correctly with the web scraper. Using the interface I seem to be able to define the object, but I'm not sure how to use it once it is defined. Below is the Data Service XML...
<data name="ComplexTypeExample">
<description>A Description</description>
<config id="GetPrices">
<property name="web_harvest_config">./samples/resources/GetPrices.xml</property>
</config>
<query id="getSonyPrices" useConfig="GetPrices">
<scraperVariable>priceInfoSony</scraperVariable>
<result element="CameraInfo" rowName="Record">
<element column="Pic" name="Pic" xsdType="string"/>
<element column="Desc" name="Desc" xsdType="string"/>
<element name="Inventory" namespace="">
<element name="Item" namespace="">
<element column="Grade" name="Grade" xsdType="string"/>
<element column="Price" name="Price" xsdType="string"/>
</element>
</element>
</result>
</query>
<operation name="getSonyPricesOperation">
<description>Gets prices of KM/Sony cameras</description>
<call-query href="getSonyPrices"/>
</operation>
</data>
What I am trying to do is figure out how to get the Inventory element to be an array of Item types. Something like this...
<Record>
<Pic>Camera.jpg</Pic>
<Desc>A camera made by some company</Desc>
<Inventory>
<Item>
<Grade>Good</Grade>
<Price>$200</Price>
</Item>
<Item>
<Grade>Not So Good</Grade>
<Price>$100</Price>
</Item>
<Item>
<Grade>Broken</Grade>
<Price>$10</Price>
</Item>
</Inventory>
</Record>
Can anyone provide some hints as to where I'm going wrong?
Looks like you have done your complex element mapping correctly according to your result set .. Are you having trouble scraping the values? If so you have to provide us with the scraping configuration, and also you have to write the xslt file also according to your complex elements.
Please refer the following guide for web scraping
I am getting this error while I am trying to test the data service on the wso2 dss
DS Fault Message: Error in
'SQLQuery.processStoredProcQuery'DS Code: DATABASE_ERRORSource Data
Service:-Name: CustomerDSLocation: \CustomerDS-1.0.0.dbsDescription:
N/ADefault Namespace: http://ws.wso2.org/dataserviceCurrent Request
Name: op1Current Params: {Name=?, NID=?}Nested Exception:-DS Fault
Message: Error in 'createProcessedPreparedStatement'DS Code:
UNKNOWN_ERRORNested Exception:-java.sql.SQLException: Parameter index
of 3 is out of range (1, 0)
any suggestions?
edited: The bds file is as follows, this is a sample case mentioned in the wso2 documentation.
<data name="CustomerDS">
<config id="default">
<property name="org.wso2.ws.dataservice.driver">com.mysql.jdbc.Driver</property>
<property name="org.wso2.ws.dataservice.protocol">jdbc:mysql://localhost:3306/CustomersDatabase</property>
<property name="org.wso2.ws.dataservice.user">root</property>
<property name="org.wso2.ws.dataservice.password">root</property>
</config>
<query id="q1" useConfig="default">
<sql>call getCustomer(?,?,?,?)</sql>
<result element="Entries" rowName="Entry">
<element name="Flag" column="Flag" xsdType="xs:integer" optional="true" />
<element name="Customer" column="Customer" xsdType="xs:string" optional="true" />
</result>
<param name="NID" sqlType="STRING" ordinal="1" />
<param name="Name" sqlType="STRING" ordinal="2" />
<param name="Flag" sqlType="INTEGER" type="OUT" ordinal="3" />
<param name="Customer" sqlType="STRING" type="OUT" ordinal="4" />
</query>
<operation name="op1">
<call-query href="q1">
<with-param name="NID" query-param="NID" />
<with-param name="Name" query-param="Name" />
</call-query>
</operation>
</data>
WHAT WORKED FOR ME!!
I found the reference code at http://svn.wso2.org/repos/wso2/people/kasun/wso2con_2013/starbucks_2.0/dss/StarbucksDataService.dbs
and the procedure call that is finally working for me is (which changes in procedure itself)
<data name="CustomerDS">
<config id="default">
<property name="org.wso2.ws.dataservice.driver">com.mysql.jdbc.Driver</property>
<property name="org.wso2.ws.dataservice.protocol">jdbc:mysql://localhost:3306/CustomersDatabase</property>
<property name="org.wso2.ws.dataservice.user">root</property>
<property name="org.wso2.ws.dataservice.password">root</property>
</config>
<query id="q1" useConfig="default">
<sql>call getCustomer(?,?)</sql>
<result element="Entries" rowName="Entry">
<element name="Flag" column="Flag" xsdType="xs:integer" optional="true" />
<element name="Customer" column="Customer" xsdType="xs:string" optional="true" />
</result>
<param name="NID" sqlType="STRING" ordinal="1" />
<param name="Name" sqlType="STRING" ordinal="2" />
<param name="Flag" sqlType="INTEGER" type="OUT" ordinal="3" />
<param name="Customer" sqlType="STRING" type="OUT" ordinal="4" />
</query>
<operation name="op1">
<call-query href="q1">
<with-param name="NID" query-param="NID" />
<with-param name="Name" query-param="Name" />
</call-query>
</operation>
</data>
And the tentative working procedure call for now is :
DELIMITER //
CREATE procedure getCustomer(NID varchar(200),Name varchar(200))
BEGIN
DECLARE id varchar(200);
DECLARE flag int;
SET Flag = 0;
SET id = CONCAT(NID, '_' , Name);
INSERT INTO Customer(NID, Name, customerID) VALUES(NID, Name, id);
select flag, customerid from customer where customerID = id;
END//
In the query q1 call getCustomer(?,?,?,?) takes 4 arguments and in the input mapping list there are only 2 input params (IN Only). This must be the reason for the this exception. Please refer this tutorial.