def post(self):
selector = self.request.get('search')
search = db.GqlQuery("SELECT * FROM Product WHERE productName = :selector", selector=selector)
products = search.fetch(10)
values = {
'products' : products
}
doRender(self, 'search.html', values)
above code is for search function from my Product category...
Actually i tried to use the code "Select * From Product Where productName like %:selector%"
for my search function, but i couldn't use this code....
Is there anyother GQL code which is substitution of 'SQL-LIKE query'??
There is no equivalent of SQL's LIKE in App Engine. You can however do something like
blurred_product_name = selector[:-2]
search = db.GqlQuery('SELECT * FROM Product where productName > ',
blurred_product_name)
So, if you have products with the name Product-1, Product-2, Product-3 and the search term is "Product", your blirred_product_name will be "Produc" which will return all the three possibilities in this case.
Be careful with indexes however.
Alternatively you can very well use SearchableModel http://www.billkatz.com/2008/8/A-SearchableModel-for-App-Engine and get this done easily.
Related
in python my code to fetch data from the table is as follows:
posts = get_db().execute(
'SELECT * FROM post WHERE (? = ?) ORDER BY created DESC', (name, value)
).fetchall()
name and value are variables depending on what the user clicks on the page.
The code won't work... how should it be written???
Addon:
Searching for a solution I bumped into the following:
def get_posts(name, tag):
posts = get_db().execute(
"""SELECT * FROM post WHERE ({} = ?)""".format(name), (tag,)
).fetchall()
But didn't work for me too...
I have an enquiry form which works from a view with a custom query. The form has filters, which I use in the executeQuery method of the view on the form to add ranges on various fields.
A new requirement is to filter based on two fields in the query.
Example: The PurchLine table is one of the tables in the query.
A new range is needed :
if PurchLine.ItemId != “” then
filter by PurchLine.PurchStatus == None
but, if the Item has a SPECIFIC value,
then filter by PurchStatus == Received.
(Ok, this is just an example!).
I am unable to modify my query to add a range on the PurchStatus based on the Item field.
I know exactly how the string value of the query must look, but how can I modify the query string?
The current query string looks like this (if I breakpoint on super in executeQuery):
SELECT FIRSTFAST * FROM OpenPOLinesView(OpenPOLinesView) WHERE ((CreatedDateTime<='2016-11-30T23:59:59')) AND ((VendAccount = N'S000001048'))
I want to add this at the end:
AND (((ItemId = N'') AND (PurchStatus = 0)) OR ((ItemId = N'XXX123') AND (PurchStatus = 2)))
How can I modify the query string in code?
You can use query expression for this, e.g.
queryBuildRange.value(strFmt('((%1 == %2) || ((%1 == %3) && (%4 == "%5")))',
fieldStr(InventTable, ItemType),
any2int(ItemType::Service),
any2int(ItemType::Item),
fieldStr(InventTable, ProjCategoryId),
queryValue("Spares")));
Please refer to this link Using Expressions in Query Ranges [AX 2012] for details.
Any idea how to select all cmis:document with specified tags or category? I'm using Apache Chemistry. I'm guessing I should use JOINs but can't figure out how to do so, I'm still having trouble drawing relationships between types.
I found this piece of code:
testDoc = session.getObjectByPath("/test/testfolder1/test1.txt")
catIds = testDoc.getPropertyValue("cm:categories")
for (catId in catIds) {
cat = session.getObject(catId)
println(cat.name)
}
But so far I plan to use prepared statement, because i'm interested in the use of IN_FOLDER, just like this:
QueryStatement qs = session.createQueryStatement("SELECT ?, ? FROM ? WHERE ? > TIMESTAMP ? AND IN_FOLDER(?) OR ? IN (?)");
The goal of my request is to get all documents with certain category and contained in a folder (soon I'll have too add criteria on tag)
Thanks for your help
That's how I did for tags:
SELECT * FROM cmis:folder AS F JOIN cm:taggable AS T ON T.cmis:objectId = F.cmis:objectId WHERE T.cmis:name = 'Agency Files'
But it won't work if I decide to add the IN_FOLDER condition
I have an ASP.NET Web API app using Oracle's Entity Framework driver. I have an entity defined for a view as follows:
CREATE OR REPLACE FORCE VIEW "PHASE_TWO"."EDIPRODUCT" ("ID", "STK_NUM", "TITLE", "ISBN", "UPC", "ITEMNO", "LONGFORMAT", "ABRIDGED", "WEB_TITLES_ID", "OCLC", "GENRE", "RELYEAR", "ORIG_REL", "LANG", "ORIG_STKNUM", "PUBLISHER", "PEOPLELIST", "SALES_ORG", "NOT_AVAIL") AS
SELECT sap_product.id,
sap_product.stk_num,
sap_product.longdesc AS title,
sap_product.isbn,
sap_product.upc,
sap_product.itemno,
sap_product.longformat,
sap_product.abridged,
mwt_product.web_titles_id,
mwt_product.oclc,
mwt_product.genre,
mwt_product.RELYEAR,
sap_product.orig_rel,
sap_product.lang,
sap_product.orig_stknum,
UPPER (publisher.name) publisher,
(SELECT LISTAGG (p.FULLNAME, ', ') WITHIN GROUP (
ORDER BY pp.rank) AS People
FROM people p
JOIN product_people pp
ON p.id = pp.peopleid
WHERE pp.stk_num = sap_product.stk_num
GROUP BY pp.STK_NUM
) PeopleList,
sppg.PRICING_TYPE as sales_org,
sap_product.not_avail
FROM sap_product
JOIN mwt_product ON sap_product.stk_num = mwt_product.stk_num
JOIN publisher ON mwt_product.publisherid = publisher.id
JOIN SAP_PRODUCT_PRICING_GROUP sppg on sppg.STK_NUM = mwt_product.stk_num and sppg.MARKED_FOR_DELETION = 0
WHERE mwt_product.WEB_PRODUCTS_ID > 0;
This view works as expected in SQL Developer. My getEDIPRODUCT function (yes, it's VB.NET) in my controller is as follows:
' GET: odata/EDIPRODUCTs
<EnableQuery>
Function GetEDIPRODUCT() As IQueryable(Of EDIPRODUCT)
Dim results As IQueryable
results = db.EDIPRODUCT
For Each _product In results
Console.Write(_product)
Next
Return results
End Function
I just added the for loop in order to inspect the results. What I see when I inspect the results is the same product record is returned for each row. The value for the ID is duplicate and the only other field that should have variant values (sppg.PRICING_TYPE as sales_org) also just repeats.
I have other views where this does not occur. The correct number of records are always returned, but the first record retrieved is always just repeated in each row of the result set. Any idea what could be going on here?
I never actually resolved this issue and am still interested in why this fails, but I rewrote the portion of the app that uses this view to use OData's $expand to retrieve the related data.
I have a custom table with a list of sales orders I want to post picking lists for.
How can I pass them all at once to the SalesFormLetter object to pick them in a group?
I see SalesFormLetter_PickingList\newJournalList is being called, and I was wondering if there was a way I could just pass a simple RecordSortedList in of the sales orders I wanted to pick. That list is of the wrong table though...so that wouldn't work. It looks like I can somehow pass a query but I'm not exactly sure how to do that. Here is the basic code I'm using to post the picking lists:
salesFormLetter = SalesFormLetter::construct(DocumentStatus::PickingList);
salesFormLetter.update(SalesTable::find(_salesId), today(), SalesUpdate::All, AccountOrder::None, NoYes::No, NoYes::Yes);
This involves setting up a query to select your sales orders then calling the chooseLines to select the orders.
by: Jubal1234Posted on 2010-07-27 at 04:13:28ID: 33296972
Found the solution:
SalesFormLetter salesFormLetter;
QueryRun queryRun;
Query query;
str strSalesTable = "V683904, V683905, V683906";
;
salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
query = new Query(QueryStr(SalesUpdate));
query.dataSourceTable(tablenum(SalesTable)).addRange(fieldnum(SalesTable, SalesId)).value(strSalesTable);
queryRun = new QueryRun(query);
salesFormLetter.chooseLinesQuery(queryRun);
salesFormLetter.transDate(systemdateget());
salesFormLetter.specQty(SalesUpdate::All);
salesFormLetter.printFormLetter(false);
salesFormLetter.createParmUpdate();
salesFormLetter.chooseLines(null,true);
salesFormLetter.reArrangeNow(true);
salesFormLetter.run();
Case closed