I have a problem for concatenate different String in one String. The code works, but I have a word that is inserted between each of my Strings. Thank you in advance for your response.
let locality = String(self.locality)
let postalCode = String(self.postalCode)
let administrativeArea = String(self.administrativeArea)
let country = String(self.country)
let addressFull = locality + ", " + postalCode + " " + administrativeArea + ", " + country
print(addressFull)
Output
Optional("..."), Optional("...") Optional("..."), Optional("...")
self.locality and your other properties are Optional strings, so you have to safely unwrap them before using them.
Example with if let:
if let locality = String(self.locality), let postalCode = String(self.postalCode), let administrativeArea = String(self.administrativeArea), let country = String(self.country) {
let addressFull = locality + ", " + postalCode + " " + administrativeArea + ", " + country
print(addressFull)
}
You should study the documentation about Optionals, it's a very important concept in Swift.
Related
Every it-codigo has 1 or more es-codigo. I'm trying to find all the es-codigo of the it-codigo input, but it's taking too long. Did I do anything wrong in my code? For what I have seen, it's all right, unless there's something I don't know about that I'm doing wrong. Is QUERY-PREPARE() the best option in this case?
DEF VAR qEstrutura AS CHAR.
IF pi-cod-emitente <> 0 THEN DO:
qEstrutura = " WHERE item-cli.cod-emitente = " + QUOTER(pi-cod-emitente).
END.
IF pc-it-codigo <> "" THEN DO:
IF qEstrutura = "" THEN
qEstrutura = " WHERE estrutura.it-codigo = " + QUOTER(pc-it-codigo).
ELSE
qEstrutura = qEstrutura + " AND estrutura.it-codigo = " + QUOTER(pc-it-codigo).
END.
IF pc-item-cli <> "" THEN DO:
IF qEstrutura = "" THEN
qEstrutura = " WHERE item-cli.item-do-cli = " + QUOTER(pc-item-cli).
ELSE
qEstrutura = qEstrutura + " AND item-cli.item-do-cli = " + QUOTER(pc-item-cli).
END.
cQuery = cQuery + " FOR EACH item-cli, ".
cQuery = cQuery + " EACH estrutura ".
cQuery = cQuery + qEstrutura + " BREAK BY estrutura.es-codigo".
QUERY qConsulta:QUERY-PREPARE(cQuery).
QUERY qConsulta:QUERY-OPEN().
GET FIRST qConsulta.
DO WHILE AVAILABLE item-cli:
IF QUERY qConsulta:FIRST-OF(1) THEN DO:
CREATE tt-estrutura.
ASSIGN
tt-estrutura.it-codigo = estrutura.it-codigo
tt-estrutura.es-codigo = estrutura.es-codigo
.
GET NEXT qConsulta.
END.
END.
QUERY qConsulta:QUERY-CLOSE().
FOR EACH tt-estrutura:
DISP tt-estrutura.
END.
I believe it's the QUERY-OPEN() that takes time. Not QUERY-PREPARE().
Your query is only performing selection (WHERE) and sort (BY) on the second table. That makes is difficult to utilize indizes. The OpenEdge ABL query engine does not support flipping the buffer-sequence. Try turning the query around:
FOR EACH estrutura WHERE ......, FIRST item-cli.
What is the replacement for SetCustomMetaQuery in Broker query Mechanism (Tridion 2011)?
I got lots of help through this post posted by me earlier.
for
query.SetCustomMetaQuery("KEY_NAME='Key' AND KEY_STRING_VALUE >= 'Yes'");
I tried
CustomMetaValueCriteria criteria1 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("Key"), "Yes");
mainCriteria =CriteriaFactory.And(mainCriteria, criteria1);
query.Criteria = mainCriteria;
But I am stuck at below two examples in one of the filter CTs.
query.SetCustomMetaQuery("(((KEY_NAME='EventStartDate' AND
KEY_DATE_VALUE >= '" + lowerDate + "')) or
((KEY_NAME='EventEndDate' AND KEY_DATE_VALUE >= '" + lowerDate + "')))"")
and
query.SetCustomMetaQuery("KEY_NAME = 'Publication_Issue_Date' and
((convert(varchar(10), key_date_value, 101) = convert(varchar(10),
cast('" + sIssueDate + "' as datetime), 101)) or
key_string_value like '%" + dtIssue[%=nNumber%].Year + "-0" + dtIssue[%=nNumber%].Month + "-" + dDay[%=nNumber%] + "%')");
Could any please help me with this?
Thought I'd have a stab at this so could be way off!
How's this for the first example:
CustomMetaValueCriteria criteria1 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("EventStartDate"), lowerDate, Criteria.GreaterThanOrEqual);
CustomMetaValueCriteria criteria2 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("EventEndDate"), lowerDate, Criteria.GreaterThanOrEqual);
OrCriteria or = new OrCriteria(criteria1, criteria2);
Assumes that "lowerDate" is a DateTime.
The second one is a bit confusing, it looks like its checking for the existence of "Publication_Issue_Date" and any KEY_DATE_VALE that equals the sIssueDate variable OR that there's a string metadata value in the from of a date. So is that going to be something like?
CustomMetaKeyCriteria criteria1 = new CustomMetaKeyCriteria ("Publication_Issue_Date")
CustomMetaValueCriteria criteria2 = new CustomMetaValueCriteria(sIssueDate);
AndCriteria andCriteria = new AndCriteria(criteria1, criteria2);
string dt = dtIssue[%=nNumber%].Year + "-0" + dtIssue[%=nNumber%].Month + "-" + dDay[%=nNumber%];
CustomMetaValueCriteria criteria3 = new CustomMetaValueCriteria(dt, Criteria.Like)
OrCriteria or = new OrCriteria(andCriteria, criteria3);
Cheers
Please try with:
CustomMetaValueCriteria criteria1 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("Key"), "Yes", Criteria.GreaterThanOrEqual);
Let me know if this works.
I have this 2 SQLite scripts:
both tested by direct input into SQLite.
def getOutgoingLinks(self, hostname):
t = (hostname,)
result = self.__cursor.execute("SELECT url.id, hostname.name, url.path, linking_to.keyword, siteId.id " +
"FROM url, hostname, linking_to, " +
"(SELECT url.id FROM url, hostname " +
"WHERE hostname.name = (?) " +
"AND hostname.id = url.hostname_id " +
") AS siteId " +
"WHERE linking_to.from_id = siteId.id " +
"AND linking_to.to_id = url.id " +
"AND url.hostname_id = hostname.id", t)
result = result.fetchall()
return result
def getIncommingLinks(self, hostname):
t = (hostname,)
result = self.__cursor.execute("SELECT url.id, hostname.name, url.path, linking_to.keyword, siteId.id " +
"FROM url, hostname, linking_to, " +
"(SELECT url.id FROM url, hostname " +
"WHERE hostname.name = (?) " +
"AND hostname.id = url.hostname_id " +
") AS siteId " +
"WHERE linking_to.to_id = siteId.id " +
"AND linking_to.from_id = url.id " +
"AND url.hostname_id = hostname.id", t)
result = result.fetchall()
return result
The getIncommingLinks() methond works very well, but getOutgoingLinks() causes an infinite Loop when python trys to execute the SQL statement. Any ideas what went wrong?
Rewrite your Select statements without select ...( Select ...) - thats very bad style. The result may solve your problem.
If by infinite loop you mean that the function doesnt ever get to return a value, I had the same problem.
Found the solution in Why python+sqlite3 is extremely slow?. With large tables it becomes a performance issue with the version shipped with python 2.7. I solved it by upgrading sqlite3 as specified here: https://stackoverflow.com/a/3341117/3894804
Is there a way to search for only givenName or LastName or emailaddress of a Contact in GAL?. Currently I have these code:
Private Sub QuickSearch() 'Working!
Dim oApp As New Outlook.Application
Dim eu As Outlook.ExchangeUser = oApp.GetNamespace("MAPI").AddressLists("Global Address List").AddressEntries("Justin Timberlake").GetExchangeUser()
If Not eu Is Nothing Then
response.write(eu.Name + ": " + eu.Alias + ", " + eu.FirstName + ", " + eu.LastName + ", " + eu.MobileTelephoneNumber + ", " + eu.Department + ", " + eu.PrimarySmtpAddress)
End If
oApp.Quit()
End Sub
Well, this one works like a Quick Search through the AddressList GAL. but one problem arises is that for example I have these contact names:
- Justin Bieber
- Justin Timberlake
And I searched for Justin, only Justin Bieber will be the result as it is the first one to be seen on the list.
You need to stop at AddressEntries and then iterate through the list
Dim oApp As New Outlook.Application
Dim aeList As Outlook.AddressEntries = oApp.GetNamespace("MAPI").AddressLists("Global Address List").AddressEntries("Justin Timberlake")
If Not aeList Is Nothing Then
For Each ae As Outlook.AddressEntry aeList
Dim eu As Outlook.ExchangeUser = ae.GetExchangeUser()
response.write(eu.Name + ": " + eu.Alias + ", " + eu.FirstName + ", " + eu.LastName + ", " + eu.MobileTelephoneNumber + ", " + eu.Department + ", " + eu.PrimarySmtpAddress)
Next
End If
I'm using advance search option in library project
Here is idea :
i have 6 different fields to allow search if i give the option for user to enter value in any of 6 option or enter combined fields how to use sql query to retrieve the value.
For example the fields are author, publication, price, subject, edition, bookid
and if user enter only one value i could search but if user enter more than one if i try combinations then there are many combination.
Please suggest me how to define the query?
you can do something like..
string strFilters = string.Empty;
if (author != "" )
{
strFilters += " Author = " + yourAuthorString + " and ";
}
if (publication != "")
{
strFilters += " publication = " + yourpublicationString + " and ";
}
if (price != "")
{
strFilters += " price = " + priceValue + " and ";
}
if (subject != "")
{
strFilters += " subject = " + yoursubjectString + " and ";
}
if (edition != "")
{
strFilters += " edition = " + youreditionString + " and ";
}
if (strFilters.Length > 3)
{
strFilters = strFilters.Remove(strFilters.Length - 5, 5);
}