How to query ARCGIS REST Service via ajax with street address - ajax

Not very familiar with the necessary GIS concepts so this is a beginner question. From my web app I am querying a GIS REST Service using this query:
require([
"dojo/dom", "dojo/on",
"esri/tasks/query", "esri/tasks/QueryTask", "dojo/domReady!"
], function (dom, on, Query, QueryTask) {
var queryTask = new QueryTask("http://gis.something.org/arcgis/rest/services/XXXX/Operational/MapServer/6");
var query = new Query();
query.returnGeometry = false;
query.outFields = [
"DISTRICTID "
];
query.where = "SUBID = '" + SUBJID + "'";
queryTask.execute(query, showResults);
In this scenario I had a subject ID (SUBID) which I used for the query to return which district the subject falls in (i.e. the respective DistrictID). I now want to query the service by street address, rather than by SUBID. Any pointers how to structure the query in this case?
thank you!

in query.where, just add ' AND ' or ' OR ' to concatenate the where attribute with other conditions...
example:
query.where = "SUBID = '" + SUBJID + "'" + ' AND ' + "otherAttr = " + otherVar;

Any pointers query in this case
var q = new Query();
var query = "SUBID = '" + SUBJID + "'";
query = query + " and " + "attr = " + attrValue
q.where = query;

Related

cypress use value outside .then() block

i have a case where i enter a searchTerm to a search field. Then I want to count the results shown to randomly select one of the entries. But I cannot realize it with cypress
let countOfElements = "";
cy.get(this.SEARCH_RESULT + ' > a').then($elements => {
countOfElements = $elements.length;
cy.log(countOfElements)
cy.log("Found " + countOfElements + " results for search term + " + searchTerm)
});
cy.get(this.SEARCH_RESULT + ' > a').invoke('val').as('searchEntries')
//This is obviosly not working, but I don't get how to fix this.
let randomNumber = this.getRandomNumberBetweenTwoValues(0, cy.get('#searchEntries')));
cy.get(this.SEARCH_RESULT + ' > a').eq(randomNumber).click()
I tried different things, like storing the value with .as() but I never seem to have access to the value outside a .then() block. So how I can use the value in my "getRandomNumber..." function to decide with entry in the result list shall be selected?
Pls help. thx
let countOfElements = "";
cy.get(this.SEARCH_RESULT + ' > a').then($elements => {
countOfElements = $elements.length;
cy.log(countOfElements)
cy.log("Found " + countOfElements + " results for search term + " + searchTerm)
});
cy.get(this.SEARCH_RESULT + ' > a').invoke('val').as('searchEntries')
//This is obviosly not working, but I don't get how to fix this.
let randomNumber = getRandomNumberBetweenTwoValues(0, this.searchEntries);
cy.get(this.SEARCH_RESULT + ' > a').eq(randomNumber).click()
Something like this could work. If this.searchEntries give undefined error then make the block function(){} instead of ()=>{}

How to add a dynamic where in #Query?

I need to add my where conditions based in my filter object. If some value in the filter object is null, isn't necessary add the where condition of this parameter.
How to add a dynamic where?
Exemple:
FilterObject{
name: "Teste";
age: null;
}
#Query(value="SELECT id FROM user WHERE name = FilterObject.name", nativeQuery = true)
public List<User> getUsers(???)
Other example:
FilterObject{
name: "Teste";
age: 12;
}
#Query(value="SELECT id FROM user WHERE name = FilterObject.name AND age = FilterObject.age", nativeQuery = true)
public List<User> getUsers(???)
This is a highlevel example. Isnt the correct code. But... Is the necessary to understand my question
If a parameter of my filter is null this parameter isnt used in my where
Im Using spring boot with Spring Data JPA and my Query stay in my repository a Repository.
My Original request:
#Query(value = " SELECT "
+ " solicitacao.nm_orgao AS nmOrgao, "
+ " solicitacao.ds_ano_exercicio AS exercicio, "
+ " solicitacao.nm_organismo AS nmOrganismo, "
+ " dadosBancarios.valor AS valor, "
+ " dadosBancarios.valor * dadosBancarios.vl_taxa_cambio AS valorReais, "
+ " dadosFinanceiros.vl_dotacao_disponivel AS vlDotacaoDisponivel, "
+ " solicitacao.id_solicitacao AS codigoPagamento "
+ " solicitacao.tp_solicitacao_status AS idFase, "
+ " organismo.id_orgao AS idOrgao, "
+ " solicitacao.id_organismo AS idOrganismo, "
+ " pagamentos.id_status_pagamento AS statusPagamento "
+ " FROM "
+ " tbs_solicitacao solicitacao "
+ " JOIN tbs_dados_bancarios dadosBancarios ON solicitacao.id_solicitacao = dadosBancarios.id_solicitacao "
+ " JOIN tbs_dados_financeiros dadosFinanceiros ON dadosFinanceiros.id_solicitacao = solicitacao.id_solicitacao "
+ " JOIN tbs_organismo organismo ON organismo.id_organismo = solicitacao.id_organismo "
+ " JOIN tbs_pagamentos pagamentos ON dadosFinanceiros.id_dados_financeiros = pagamentos.id_dados_financeiros ",nativeQuery = true)
List<Object[]> getRelatoriosProgramacao();
You can use Spring Data JPA specifications:
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#specifications
You simply have to implement the method toPredicate:
Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder);
In this method you get root, query and the CriteriaBuilder to create a Criteria API where predicate.
Event methods like findAll take a Specification.

Birt report parameter passing

Hi i have to pass parameter to a report...with a concat-date ....but its showing error...
like this...am having in list box with 2011-2012,2012-2013...here is my oracle query
DATE FOMART IN DATABASE:25-Mar-2012
oracle query
select tran_date,
ROUND (nvl(sum(WALKIN_WITHOUT_CGROUP),0)/ COUNT(*),2)APC
from OUTLET_PAYMODE_REPORT_FACT
Before Open:
var sqld= new String();
yearParam = params["Year"].value;
yearParam = yearParam.split("-");
startYear = yearParam[0];
endYear = yearParam[1];
this.queryText =this.queryText +" where TRAN_DATE between '" + startYear + "01-Mar-' and '" + endYear + "30-Mar-'"+
"group by tran_date"
but am getting error like this.....
org.eclipse.birt.report.data.oda.jdbc.JDBCException: SQL statement does not return a ResultSet object.
SQL error #1:ORA-01861: literal does not match format string
I think, your sql string should be
" where TRAN_DATE between '01-Mar-" + startYear +
"' and '30-Mar-" + endYear + "' " +
"group by tran_date"

Error in inserting the SQLqueries with special characters in to H2database

I have an xml which i parse to read the values of the nodes and i get these values in to a custom list for ex Validation.
Now after parsing the xml for values when i try to insert the values in to the table in the H2Database i end up getting the syntax error.
Sample xml which i parse
<DmtTask xsi:type="SqlTask">
<TaskSeverity></TaskSeverity>
<TaskCategory></TaskCategory>
<TaskTitle></TaskTitle>
<TaskMessage></TaskMessage>
<TaskCode></TaskCode>
<DSqlGenerated></DSqlGenerated>
<TaskName>VALIDATE_COMPANIES_MISSING_AVAILABILITY_DATE</TaskName>
<SqlQuery>DROP TABLE CLIENT_VALIDATION.COMPANIES_MISSING_AVAILABILITY_DATE IF EXISTS;
CREATE TABLE CLIENT_VALIDATION.COMPANIES_MISSING_AVAILABILITY_DATE AS
(SELECT * FROM CLIENT.COMPANIES WHERE AVAILABILITY_DATE = '');
</SqlQuery>
<ReportError>SELECT 'Missing Availability Date' AS ERROR_DESC,
ORGANIZATION_NAME,AVAILABILITY_DATE,COUNTRY,EMAIL_ADDRESS,INSTANT_MESSENGER_ADDRESS,REVERSE_DEBIT_CREDIT,KEEP_DEBIT_CREDIT_AND_REVERSE_SIGN
FROM CLIENT_VALIDATION.COMPANIES_MISSING_AVAILABILITY_DATE</ReportError>
<MetricSchemaName>DMTSCRIPTS</MetricSchemaName>
</DmtTask>
Dynamic Query which i wrote to update the table from code behind. TaskEditorText is an object of custom collection List
for (int i = 0; i < taskEditorText.Count; i++)
{
//string sqlGenerated = "false";
db.ExecuteNonQuery("INSERT INTO " + Schema + ".DMTScriptTasks(DmtScriptId,TaskSeverity,TaskCategory,TaskTitle,TaskMessage,TaskCode,TaskName,Execute,UpdatedUser,UpdatedTime) VALUES('" + id + "','" + taskEditorText[i].TaskSeverity + "','" + taskEditorText[i].TaskCategory + "','" + taskEditorText[i].TaskTitle + "','" + taskEditorText[i].TaskMessage + "','" + taskEditorText[i].TaskCode + "','" + taskEditorText[i].TaskName + "','" + true + "','" + CreatedUser + "','" + CreatedDate + "');");
}
Sample value which results in the syntax error
DROP TABLE CLIENT_VALIDATION.COMPANIES_INVAL_AVAILABILITY_DATE IF EXISTS;
CREATE TABLE CLIENT_VALIDATION.COMPANIES_INVAL_AVAILABILITY_DATE AS
(SELECT *
FROM CLIENT.COMPANIES
WHERE
AVAILABILITY_DATE != ''
AND
AVAILABILITY_DATE NOT LIKE '____-__-__');
I tried replacing the special characters, wrote regular expression, used Regex.Escape nothing worked for me. I don't have any control on the xml i parse. Even i am new to the H2Database. So if any knows a way to insert values of this type in to the column in the database can you please help me.
Here the database which we are using is H2DataBase ( Java database).
PreparedStatement prep = reader.Connection.prepareStatement("INSERT INTO " + Schema + ".DMTScriptTasks(DmtScriptId,TaskSeverity,TaskCategory,TaskTitle,TaskMessage,TaskCode,TaskName,Execute,UpdatedUser,UpdatedTime,SqlQuery) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
Then loop through the collection
for (int i = 0; i < taskEditorText.Count; i++)
{
prep.setString(1, id);
prep.setString(2, taskEditorText[i].TaskSeverity);
prep.setString(3, taskEditorText[i].TaskCategory);
prep.setString(4, taskEditorText[i].TaskTitle);
prep.setString(5, taskEditorText[i].TaskMessage);
prep.setString(6, taskEditorText[i].TaskCode);
prep.setString(7, taskEditorText[i].TaskName);
prep.setString(8, "true");
prep.setString(9, CreatedUser);
prep.setString(10, CreatedDate);
prep.setString(11, taskEditorText[i].SqlQuery);
//batch insert
prep.addBatch();
reader.Connection.setAutoCommit(false);
prep.executeBatch();
reader.Connection.setAutoCommit(true);
}
Here taskEditorText is a List and the database i am trying to insert values is H2Database.
Then I did batch update of the insert query.

Error getting too many character literals

var query = from s in bv.baParticularHeaders
from v in bv.baPlanColumnStructures
where x.Contains(s.Particular_Num)
select new LevelList
{
Value = 'Level ' + LTRIM(Rtrim(Convert(Char,P.Level_Num))) + ' - ',
id = 'Column ' + LTRIM(Rtrim(Convert(Char,P.Column_Num))) + ' ',
Text = v.Column_Description
};
return query.Distinct().OrderBy(o => o.Value).AsQueryable<LevelList>();
Error getting this both lines of code.
Value = 'Level ' + LTRIM(Rtrim(Convert(Char,P.Level_Num))) + ' - ',
id = 'Column ' + LTRIM(Rtrim(Convert(Char,P.Column_Num))) + ' ',
Can any body help me out how to convert this in LINQ?
Thanks
You can't just cut and paste SQL, rearrange it and hope to get a valid LINQ query. The aim is to write the appropriate C# code, which is translated into SQL. In this case I suspect you want:
var query = from s in bv.baParticularHeaders
from v in bv.baPlanColumnStructures
where x.Contains(s.Particular_Num)
select new LevelList
{
Value = "Level " + P.Level_Num + " - ";
id = "Column " + p.Column_Num + " ",
Text = v.Column_Description
};
return query.Distinct().OrderBy(o => o.Value).AsQueryable();
Note the string literals - "Level " not 'Level '. The code has to be valid C# first.
(Assuming Level_Num and Column_Num are numbers, I can't see why it would make sense to trim them.)

Resources