How to set %Dictionary.StorageSQLMapDataDefinition.RetrievalCode? - intersystems

How can I do this:
<Data name="hyperlink">
<RetrievalCode>
<![CDATA[set res=""
set colId=""
for
{
set colId = $order( ^ohtest("mltab","main","Dta",{L4},colId) )
quit:(colId = "")
set indexTab = $g(^ohtest("mltab","main","Dta",{L4},colId,"Index"))
if indexTab'="" {
set res = res_"<hyperlinkIndexTab><colId>"_colId_"</colId><iTab>"_indexTab_"</iTab></hyperlinkIndexTab>"
}
}
s {hyperlink}=res]]></RetrievalCode>
</Data>
programatically?
I have:
set global = "^ohtest"
set iTab="main"
//hyperlink
set storData = ##class(%Dictionary.StorageSQLMapDataDefinition).%New()
set storData.Name = "hyperlink"
set storData.RetrievalCode = "<![CDATA[set res="""" set colId="""" for{set colId = $order( "_global_"(""mltab"","_iTab_",""Dta"",{L4},colId) ) quit:(colId = """") set indexTab = $g("_global_"(""mltab"","_iTab_",""Dta"",{L4},colId,""Index"")) if indexTab'="""" {set res = res_""<hyperlinkIndexTab><colId>""_colId_""</colId><iTab>""_indexTab_""</iTab></hyperlinkIndexTab>""}} s {hyperlink}=res]]>"
do storMap.Data.Insert(storData)
But it doesn't work. How to let generate code provided above?

your first problem is, putting CDATA declaration in code. Caché will add it without you, and then you put iTab without quotes.
set global = "^ohtest"
set iTab="main"
set data=##class(%Dictionary.StorageSQLMapDataDefinition).%New()
set data.Name="hyperlink"
set code=""
set code=code_"set res="""""_$c(13,10)
set code=code_"set colId="""""_$c(13,10)
set code=code_"for"_$c(13,10)
set code=code_"{"_$c(13,10)
set code=code_" set colId = $order( "_global_"(""mltab"","""_iTab_""",""Dta"",{L4},colId) )"_$c(13,10)
set code=code_" quit:(colId = """")"_$c(13,10)
set code=code_" set indexTab = $g("_global_"(""mltab"","""_iTab_""",""Dta"",{L4},colId,""Index""))"_$c(13,10)
set code=code_" if indexTab'="""" {"_$c(13,10)
set code=code_" set res = res_""<hyperlinkIndexTab><colId>""_colId_""</colId><iTab>""_indexTab_""</iTab></hyperlinkIndexTab>"""_$c(13,10)
set code=code_" }"_$c(13,10)
set code=code_"}"_$c(13,10)
set code=code_"s {hyperlink}=res"_$c(13,10)
set data.RetrievalCode=code
do storMap.Data.Insert(data)

Related

How to set data-attribute between image's src and alt attributes?

Order:
$img->src = 'someimage.webp';
$img->alt = null;
$img->{'data-ext'} = 'png';
$img->alt = 'somealt';
Result:
<img src="someimage.webp" alt="somealt" data-ext="png">
I'm trying to get this:
<img src="someimage.webp" data-ext="png" alt="somealt">
UPD
I found ugly solution, but this returns valid html
$img->src = 'someimage.webp" data-ext="png';
$img->alt = 'somealt';
If you want the data-attribute to be between src and alt and setting the alt to null in between, one option could be to getAllAttributes() and use krsort to sort the array keys in reverse order.
For example
$img->src = 'someimage.webp';
$img->alt = null;
$img->{'data-ext'} = 'png';
$img->alt = 'somealt';
$attrs = $img->getAllAttributes();
krsort($attrs);
$img->attr = $attrs;
echo $img->outertext();
Output
<img src="someimage.webp" data-ext="png" alt="somealt">

Classic ASP Base64, image/png -> save as image

This particular question has been asked and answered, but no matter what I try I cannot get this to work. At this point I'm somewhat ready to toss my computer out the window..
No matter what combinations i try, it still fails at:
oStream.write imagebinarydata
Here is the code with comments:
sFileName = Server.MapPath("grafer/test.png")
ByteArray = Request.Form("imageData")
ByteArray = [DATA-URI String] 'This string shows the image perfectly fine, in an image tag in the top of the page so it should be perfectly ok?
response.write ("Decoded: " & Base64Decode(ByteArray)) '<- Writes 'PNG' ?
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Set oStream = Server.CreateObject("ADODB.Stream")
oStream.type = adTypeBinary
oStream.open
imagebinarydata = Base64Decode(ByteArray)
oStream.write imagebinarydata '<- FAILS
'Error:
'ADODB.Stream error '800a0bb9'
'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
'Use this form to overwrite a file if it already exists
oStream.savetofile sFileName, adSaveCreateOverWrite
oStream.close
set oStream = nothing
response.write("success")
Function Base64Decode(ByVal vCode)
Dim oXML, oNode
Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
Set oNode = oXML.CreateElement("base64")
oNode.dataType = "bin.base64"
oNode.text = vCode
Base64Decode = Stream_BinaryToString(oNode.nodeTypedValue)
Set oNode = Nothing
Set oXML = Nothing
End Function
Function Stream_BinaryToString(Binary)
Const adTypeText = 2
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream 'As New Stream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save text/string data.
BinaryStream.Type = adTypeBinary
'Open the stream And write text/string data To the object
BinaryStream.Open
BinaryStream.Write Binary
'Change stream type To binary
BinaryStream.Position = 0
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
If Len(CharSet) > 0 Then
BinaryStream.CharSet = CharSet
Else
BinaryStream.CharSet = "us-ascii"
End If
'Open the stream And get binary data from the object
Stream_BinaryToString = BinaryStream.ReadText
End Function
If you are trying to save you can use this function
function SaveToBase64 (base64String)
ImageFileName = "test.jpg"
Set Doc = Server.CreateObject("MSXML2.DomDocument")
Set nodeB64 = Doc.CreateElement("b64")
nodeB64.DataType = "bin.base64"
nodeB64.Text = Mid(base64String, InStr(base64String, ",") + 1)
dim bStream
set bStream = server.CreateObject("ADODB.stream")
bStream.type = 1
bStream.Open()
bStream.Write( nodeB64.NodeTypedValue )
bStream.SaveToFile(Server.Mappath("Images/" & ImageFileName), 2 )
bStream.close()
set bStream = nothing
end function

How can I set the column properties(DisplayFormatString to be precise) of a aspx(devExpress) grid from code behind?

I have an aspx(devexpress) grid. Using which I generate columns dynamically from code behind.Below is the code from my grid_databinding event.
GridViewDataTextColumn bfield = new GridViewDataTextColumn();
if (TestString.YearSelectedNames.ToString().Length > 4)
{ string colName = string.Empty;
if (iCount % 2 == 0)
{
colName = TestString.YearSelectedNames.ToString().Substring(5, 4) + "-" + dtFreezing.Columns[iCount].ColumnName.ToString();
bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), colName, iCount);
}
else
{
colName = TestString.YearSelectedNames.ToString().Substring(0, 4) + "-" + dtFreezing.Columns[iCount].ColumnName.ToString().Replace('1', ' ');
bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), colName, iCount);
}
}
else
{
bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), dtFreezing.Columns[iCount].ColumnName.Trim(), iCount);
}
bfield.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
bfield.HeaderStyle.Wrap = DevExpress.Utils.DefaultBoolean.True;
bfield.Name = dtFreezing.Columns[iCount].ColumnName.Trim();
bfield.Width = Unit.Pixel(120);
bfield.VisibleIndex = iCount;
bfield.DataItemTemplate = new DevxGridViewTemplate(ListItemType.Item, typeof(Label), dtFreezing.Columns[iCount].ColumnName.Trim(), iCount);
bfield.CellStyle.HorizontalAlign = HorizontalAlign.Right;
bfield.PropertiesTextEdit.DisplayFormatString = "N2";
gridViewProductCrop.Columns.Add(bfield);
Here the line of code
bfield.PropertiesTextEdit.DisplayFormatString = "N2";
is where I am trying to set the property of the grids' column to display only two decimals after the decimal point.
This line of code doesn't seem to work in the first place.
I have even tried using "{0:0.00}" and "{0:N2}" but in vain
Possible reason being that I am writing this line of code in the grid's databinding event. But how else can I set the column properties from code behind
Try to change this code
bfield.PropertiesTextEdit.DisplayFormatString = "N2";
to
this.PropertiesTextEdit.DisplayFormatString = "N2";
i think this happen coz u loop the object(make a new object) and the properties would be overwrite.
CMIIW

Do not generate file in disk, instead send mail with data in memory

I have a piece of code that works and do:
Reads a Database , reads a template (template.htm), put data in a new file based in the template (evento.htm), read that file and send an email with the content of the file generated. Code below (I cut the database part):
<%
NomeDoTemplate= "template.htm"
CaminhoDoTemplate= Server.MapPath(NomeDoTemplate)
CaminhoDoTemplateAjustado= Mid(CaminhoDoTemplate,1,InStrRev(CaminhoDoTemplate,"\"))
NomeDoArquivo= "evento.htm"
CaminhoDoArquivo= Server.MapPath(NomeDoArquivo)
Set ManipulacaoDeArquivo= Server.CreateObject("Scripting.FileSystemObject")
Set ObjetoArquivo= ManipulacaoDeArquivo.OpenTextFile(CaminhoDoTemplate, 1)
DadosDoObjetoArquivo= ObjetoArquivo.ReadAll
ObjetoArquivo.Close
DadosDoObjetoArquivo= Replace(DadosDoObjetoArquivo, "[Cliente]", Um)
Set ObjetoArquivo= ManipulacaoDeArquivo.CreateTextFile(CaminhoDoTemplateAjustado & NomeDoArquivo)
ObjetoArquivo.Write(DadosDoObjetoArquivo)
Set ObjetoArquivo= ManipulacaoDeArquivo.OpenTextFile(CaminhoDoTemplateAjustado & NomeDoArquivo, 1)
DadosDoObjetoArquivo= ObjetoArquivo.ReadAll
Dim objCDOSYSMail
Dim objCDOSYSCon
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.server.com"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user_id"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
objCDOSYSCon.Fields.update
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = "ABC <abc#server.com>"
objCDOSYSMail.To = "sender#gmail.com"
objCDOSYSMail.Subject = "Contato"
objCDOSYSMail.HTMLBody= DadosDoObjetoArquivo
objCDOSYSMail.Send
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
%>
I would like to make this simple, skiping the step of generating the file in the disk. I would like to:
Read a Database, reads a template, put data in memory, send the mail with that data in memory.
Thanks
If I see it correctly, all you have to do is skip the part where you save the file and re-read it... I have refactored your code, gave the variables some english names so I could see what's going on, and commented out the lines you don't need:
<%
Dim TemplateName : TemplateName = "template.htm"
Dim TemplateFullPath : TemplateFullPath = Server.MapPath(TemplateName)
Dim TemplatePath : TemplatePath = Mid(TemplateFullPath,1,InStrRev(TemplateFullPath,"\"))
Dim ArchiveName : ArchiveName = "evento.htm"
Dim ArchiveFullPath : ArchiveFullPath = Server.MapPath(ArchiveName)
Dim FSO, TemplateFile, TemplateText
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set TemplateFile = FSO.OpenTextFile(TemplateFullPath, 1)
TemplateText = TemplateFile.ReadAll()
TemplateText = Replace(TemplateText, "[Cliente]", Um)
TemplateFile.Close()
' Really simple - to do this in-memory, simply don't save and re-read the file....
' Set TemplateFile = FSO.CreateTextFile(TemplatePath & ArchiveName)
' TemplateFile.Write(TemplateText)
' Set TemplateFile = FSO.OpenTextFile(TemplatePath & ArchiveName, 1)
' TemplateText = TemplateFile.ReadAll
Set TemplateFile = Nothing
Set FSO = Nothing
Dim objCDOSYSMail, objCDOSYSCon
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.server.com"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user_id"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
objCDOSYSCon.Fields.update
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = "ABC <abc#server.com>"
objCDOSYSMail.To = "sender#gmail.com"
objCDOSYSMail.Subject = "Contato"
objCDOSYSMail.HTMLBody= TemplateText
objCDOSYSMail.Send
Set objCDOSYSMail.Configuration = Nothing
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
%>
Hope this helps,
Erik
you could use several techniques:
write your own stringbuilder class
use the .net system.io.stringwriter class (yes you can use this from classic asp)
use the adodb.stream object
example stringwriter:
set sw = server.createObject("system.io.stringwriter")
sw.write_12( DadosDoObjetoArquivo )
objCDOSYSMail.HTMLBody = sw.getStringBuilder().toString()
example (adodb.stream):
set stream = server.createobject("ADODB.Stream")
with stream
.Open
.WriteText DadosDoObjetoArquivo
end with
objCDOSYSMail.HTMLBody = stream.ReadText
stream.Close

Parameterised query asp classic missing operand error

I am trying to get a paramterised query to work in asp classic. Any help appreciated
Here is the error
Microsoft OLE DB Provider for Visual FoxPro error '80040e14'
Missing operand.
/portal/jobportal/getaddress1.asp, line 141
function paramQuery()
code = ucase(request.querystring("code"))
stype = request.querystring("type")
cAddressType = request.querystring("caddresstype")
Set rs = Server.CreateObject("ADODB.recordset")
Set cmd = server.CreateObject("ADODB.Command")
If IsObject(Session("portal_conn")) Then
Set conn = Session("portal_conn")
Else
Set conn = Server.CreateObject("ADODB.Connection")
cConnString = "Provider=vfpoledb;Data Source="+session("portaldata")+"portal.dbc"
conn.open cConnString,"",""
Set Session("portal_conn") = conn
end if
cmd.ActiveConnection = conn
cmd.Prepared = true
cmd.CommandType = 1
cmd.CommandText = "SELECT * from uaddress where userid = "+cstr(session("userid"))+" and upper(name) like ? + % "+" and type = '"+ trim(cAddresstype)+"' order by add1"
set param1 = cmd.CreateParameter("#name",200,2,40)
cmd.Parameters.append param1
cmd.Parameters("#name") = code
cmd.Execute() <-- missing operand error
rs.Open cmd
end function
When using parameter for SQL like clause you need to pass the % as part of the parameter value.
Also to protect against SQL Injection attacks you really better use parameters for the other values as well:
cmd.CommandText = "SELECT * FROM uaddress WHERE userid=? AND UPPER(name) LIKE ? AND type=? ORDER BY add1"
set param1 = cmd.CreateParameter("#id", 200, 2, 40)
cmd.Parameters.append param1
cmd.Parameters("#id") = cstr(session("userid"))
set param2 = cmd.CreateParameter("#name", 200, 2, 40)
cmd.Parameters.append param2
cmd.Parameters("#name") = "%" & code & "%"
set param3 = cmd.CreateParameter("#type", 200, 2, 40)
cmd.Parameters.append param3
cmd.Parameters("#type") = trim(cAddresstype)
cmd.Execute()
You need quotes around the % character:
... +" and upper(name) like ? + '%' "+ ...
It seems like VFP does not support named parameters , just add your params in the order that apears in the query by using (?) instead of the named param and it will work.
instead of :
cmd.Parameters("#name") = code
Use :
cmd.Parameters("?") = code

Resources