I am trying to update the table with the query result using simple update query.
here is the query.
def restore(def id, def contentId) {
String hql = ""
def q = revisionService.getRevisionById(id)
hql = """UPDATE Content
SET
parentId = ${q.parent_id}
,user_id = ${q.user_id}
,inheritFromParent = ${q.inherit_from_parent}
,forceSSL = ${q.forcessl}
,title = ${q.title}
,fileName = ${q.file_name}
,fileNamePath = ${q.file_name_path}
,fileNameLookup = ${q.file_name_lookup}
,body = ${q.body}
,summary = ${q.summary}
,template = ${q.template}
,layout = ${q.layout}
,contentType = ${q.content_type}
,isNavItem = ${q.is_nav_item}
,navDepth = ${q.nav_depth}
,navOrder = ${q.nav_order}
,metaTitle = ${q.meta_title}
,metaKeywords = ${q.meta_keywords}
,metaDescription = ${q.meta_description}
,isActive = ${q.is_active}
,col1 = ${q.col1}
,col2 = ${q.col2}
,col3 = ${q.col3}
,col4 = ${q.col4}
,col5 = ${q.col5}
,col6 = ${q.col6}
,col7 = ${q.col7}
,col8 = ${q.col8}
,col9 = ${q.col9}
WHERE id = ${contentId}"""
try {
Content.executeUpdate(hql)
} catch(Exception e) {
println e
}
}
when i execute this query getting an exception saying org.springframework.orm.hibernate4.HibernateQueryException: unexpected token: about near line 7, column 50.
here is stacktrace from my terminal.
line 7:50: unexpected token: about
Message: unexpected token: about
Line | Method
->> 353 | $tt__restore in org.regionscms.ContentService$$EOqIswWO
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 48 | restore in org.regionscms.ContentController
| 198 | doFilter . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 49 | doFilter in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
| 82 | doFilter . . in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
org.springframework.orm.hibernate4.HibernateQueryException: unexpected token: about near line 7, column 50 [UPDATE org.regionscms.Content
SET
parentId = 1
,user_id = 1
,inheritFromParent = true
,forceSSL = false
,title = about us
,fileName = about-us
,fileNamePath = home/about-us
,fileNameLookup = 72635069142711694
,body = tests
,summary = tests
,template = index.gsp
,layout = Main
,contentType = Page
,isNavItem = true
,navDepth = 1
,navOrder = 2
,metaTitle = null
,metaKeywords = null
,metaDescription = null
,isActive = true
,col1 = 1045719790170831251
,col2 = 72635069142711694
,col3 = 0
,col4 = 0
,col5 = 0
,col6 = 0
,col7 = 0
,col8 = 0
,col9 = 0
WHERE id = 2]; nested exception is org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: about near line 7, column 50 [UPDATE org.regionscms.Content
SET
parentId = 1
,user_id = 1
,inheritFromParent = true
,forceSSL = false
,title = about us
,fileName = about-us
,fileNamePath = home/about-us
,fileNameLookup = 72635069142711694
,body = tests
,summary = tests
,template = index.gsp
,layout = Main
,contentType = Page
,isNavItem = true
,navDepth = 1
,navOrder = 2
,metaTitle = null
,metaKeywords = null
,metaDescription = null
,isActive = true
,col1 = 1045719790170831251
,col2 = 72635069142711694
,col3 = 0
,col4 = 0
,col5 = 0
,col6 = 0
,col7 = 0
,col8 = 0
,col9 = 0
WHERE id = 2]
see the manual for executeUpdate how to properly use a param map like this:
Content.executeUpdate("UPDATE Content c SET parentId = :parentId, ... WHERE id = :contentId",
[cotentId: contentId, parentId: q.parentId, ...])
Code like yours is basically the road to SQL-Injection. The problem here is the use of GString replacements, which leads to invalid SQL (it should be 'about us' and not about us)
Related
Making a game in GameMaker and I'm having a problem where the variable is not set and I'm not sure why. When pressing down on either W,A,S, or D and clicking LMB it works but crashes if I pressing down on W,A,S, or D then let go and afterwards click LMB.
Code:
var look
var bullet
if (keyboard_check(ord("A"))){
x = x - 5;
sprite_index = spr_west_hiro
image_xscale = 3
image_yscale = 3
look = 180
} else if (keyboard_check(ord("D"))){
x = x + 5;
sprite_index = spr_east_hiro
image_xscale = 3
image_yscale = 3
look = 0
} else if (keyboard_check(ord("S"))){
y = y + 5;
sprite_index = spr_south_hiro
image_xscale = 3
image_yscale = 3
look = 270
} else if (keyboard_check(ord("W"))){
y = y - 5;
sprite_index = spr_north_hiro
image_xscale = 3
image_yscale = 3
look = 90
}
//------------------------------------------------------------------------------
if (keyboard_check_released(ord("A"))){
sprite_index = spr_idlewest_hiro
image_xscale = 3
image_yscale = 3
look = 180
} else if (keyboard_check_released(ord("D"))){
sprite_index = spr_idleast_hiro
image_xscale = 3
image_yscale = 3
look = 0
} else if (keyboard_check_released(ord("S"))){
sprite_index = spr_idlesouth_hiro
image_xscale = 3
image_yscale = 3
look = 270
} else if (keyboard_check_released(ord("W"))){
sprite_index = spr_idlenorth_hiro
image_xscale = 3
image_yscale = 3
look = 90
}
//--------------------------------------------------------------------------------
if (mouse_check_button_pressed(mb_left)){
var bullet = instance_create_layer(x,y, "Instances", obj_bullet)
bullet.direction = look
}
Error:
ERROR!!! :: ############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_hiro:
local variable look(100001, -2147483648) not set before reading it.
at gml_Object_obj_hiro_Step_0 (line 61) - bullet.direction = look
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_hiro_Step_0 (line 61)
I have reviewed the code multiple times and I am still stumped. Particularly because of the fact that it seems as though the variable doesn't save the coefficient set to it despite the fact that it should when W,A,S or D is pressed down then released.
Firstly, you would want to assign a value to your look variable, as otherwise it will remain not set to anything if no buttons had been pressed.
Secondly, you may want to do so in Create event, as you probably want your character to shoot in last pressed direction, not just "somewhere"
I am trying to compare if an array is a subset of other and use it in another query. I could get the comparision method working. However, if I use the compare method in another query I get an error saying "Left and right side of the relational operator must be scalars" This hints that the comparearrays is not reutrning a scalar. Any ideas?
let x = parsejson('["a", "b", "c"]');
let y = parsejson('["a", "b", "c"]');
let z = parsejson('["b","a"]');
let comparearrays = (arr1:dynamic, arr2:dynamic)
{
let arr1Length = arraylength(arr1);
let total =
range s from 0 to arr1Length-1 step 1
| project dat = iff(arr1[s] in (arr2), true , false)
| where dat == true
| count;
total | extend isEqual= iff(Count == arr1Length,'true','false') | project
tostring(isEqual)
};
//comparearrays(z, x)
datatable (i:int) [4] | project i | where comparearrays(x,y) == 'true'
You are correct in your understanding - the current implementation returns a table with a single row and single column, but have no fear - toscalar to the rescue:
let x = parsejson('["a", "b", "c"]');
let y = parsejson('["a", "b", "c"]');
let z = parsejson('["b","a"]');
let comparearrays = (arr1:dynamic, arr2:dynamic)
{
let arr1Length = arraylength(arr1);
let result =
range s from 0 to arr1Length-1 step 1
| project dat = iff(arr1[s] in (arr2), true , false)
| where dat == true
| count
| extend isEqual = iff(Count == arr1Length,'true','false')
| project tostring(isEqual);
toscalar(result)
};
//comparearrays(z, x)
datatable (i:int) [4] | project i | where comparearrays(x,y) == 'true'
You do have a bug in the comparearrays functions, since comparearrays(z, x) returns true which is not correct....
I am trying to make groupings using a CListCtrl trough the following code:
LVGROUP lg = { 0 };
lg.cbSize = sizeof(lg);
lg.state = LVGS_NORMAL | LVGS_COLLAPSIBLE;
lg.mask = LVGF_GROUPID | LVGF_HEADER | LVGF_STATE | LVGF_ALIGN | LVGF_STATE | LVGF_DESCRIPTIONTOP | LVGF_DESCRIPTIONBOTTOM | LVGF_FOOTER | LVGF_TASK | LVGF_SUBTITLE | LVGF_SUBSET;
lg.uAlign = LVGA_HEADER_LEFT | LVGA_FOOTER_RIGHT;
LVITEM item = { 0 };
item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_GROUPID;
item.iSubItem = 0;
item.state = 0;
item.stateMask = LVIS_SELECTED;
CString s;
lg.iGroupId = 0;
s = L"Office";
lg.pszHeader = s.GetBuffer();
lg.cchHeader = s.GetLength();
pListCtrl->InsertGroup(lg.iGroupId, &lg);
item.iGroupId = 0;
s = "Pen";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
s = "Pencil";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
lg.iGroupId = 1;
s = L"Workshop";
lg.pszHeader = s.GetBuffer();
lg.cchHeader = s.GetLength();
pListCtrl->InsertGroup(lg.iGroupId, &lg);
item.iGroupId = 1;
s = "Hammer";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
s = "Drill";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
s = "Saw";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
but everything is shown ungrouped
How can I make the groups work as they should?
It turns out there is the need of a manifest, which I added to stdafx.h
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
I got some code written in a function in VBA, but I'm stuck on how to return the output values areaAnswer1 & areaAnswer2 inside the if - else statments. I'm still new to this. Any help & suggestions are very much appreciated.
Function dateArea(inputDate1 As Date, t1 As Date, t2 As Date, duration As Integer, output As Integer) As Integer
endOfYear = Workbook.Date(Year(inputDate1), 12, 31)
inputDate2 = Workbook.Date(Year(inputDate1) + 1, Month(inputDate1), Day(inputDate1))
endOfDate1 = Workbook.Date(Year(inputDate1) + duration, Month(inputDate1), Day(inputDate1))
endOfDate2 = Workbook.Date(Year(inputDate2) + duration, Month(inputDate2), Day(inputDate2))
areaBase1 = endOfYear - inputDate1
areaBase2 = inputDate2 - endOfYear
totalArea1 = areaBase1 * 365
totalArea2 = areaBase2 * 365
triangleBase1 = endOfDate1 - inputDate1
triangleHypo1 = Workbook.Sqrt((365 * 365) + (triangleBase1 * triangleBase1))
triangleBase2 = t1 - inputDate2
triangleHypo2 = triangleHypo1 * triangleBase2 / triangleBase1
triangleHeight2 = Workbook.Sqrt((triangleHypo2 * triangleHypo2) - (triangleBase2 * triangleBase2))
triangleArea2 = (triangleBase2 * triangleHeight2) / 2
triangleBase3 = (inputDate2 - endOfYear) + (t1 - inputDate2)
triangleHypo3 = triangleBase3 * triangleHypo2 / (t1 - inputDate2)
triangleHeight3 = Workbook.Sqrt((triangleHypo3 * triangleHypo3) - (triangleBase3 * triangleBase3))
triangleArea3 = (triangleBase3 * triangleBaseHeight3) / 2
areaDiffBot2 = triangleArea3 - triangleArea2
triangleBase4 = 365 + (t1 - inputDate2)
triangleHypo4 = triangleBase4 * triangleHeight2 / (t1 - inputDate2)
triangleHeight4 = Workbook.Sqrt((triangleHypo4 * triangleHypo4) - (triangleBase4 * triangleBase4))
triangleArea4 = (triangleBase4 * triangleHeight4) / 2
areaDiffBot1 = triangleArea4 - triangleArea3
triangleHeight5 = 365 * (endOfDate1 - t2) / triangleBase1
triangleHypo5 = Workbook.Sqrt((triangleHeight5 * triangleHeight5) + ((endOfDate1 - t2) * (endOfDate1 - t2)))
triangleArea5 = (endOfDate1 - t2) * triangleHeight5 / 2
triangleBase6 = (endOfDate1 - t2) + areaBase1
triangleHeight6 = (triangleBase6) * 365 / (endOfDate1 - t2)
triangleHypo6 = Workbook.Sqrt((triangleBase6 * triangleBase6) + (triangleHeight6 * triangleHeight6))
triangleArea6 = (triangleBase6 * triangleHeight6) / 2
areaDiffTop1 = triangleArea6 - triangleArea5
triangleBase7 = triangleBase6 + areaBase2
triangleHeight7 = triangleBase7 * triangleHeight6 / triangleBase6
triangleHypo7 = Workbook.Sqrt((triangleBase7 * triangleBase7) + (triangleHeight7 * triangleHeight7))
triangleArea7 = (triangleBase7 * triangleHeight7) / 2
areaDiffTop2 = triangleArea7 - triangleArea6
totalUsedArea1 = areaDiffTop1 + areaDiffBot1
totalUsedArea2 = areaDiffTop2 + areaDiffBot2
areaAnswer1 = totalArea1 - totalUsedArea1
areaAnswer2 = totalArea2 - totalUsedArea2
If output = 1 Then
ElseIf output = 2 Then
ElseIf output = 3 Then
Else
End If
End Function
In VBA you set the return value by assigning it to the function like this:
areaAnswer1 = totalArea1 - totalUsedArea1
areaAnswer2 = totalArea2 - totalUsedArea2
If output = 1 Then
dateArea = areaAnswer1
ElseIf output = 2 Then
dateArea = areaAnswer2
ElseIf output = 3 Then
' ...etc
Note that the assignment to the function does not exit the function. In this case you don't need that immediate exit, as you are already at the end of it. But in some cases you'll want to exit the function as soon as you have assigned the return value:
Exit Function
Just have the function equal a typed value or one of the variables at the end.
select case output
case 1
dateArea = totalUsedArea1
case 2
dateArea = totalUsedArea2
case 3
dateArea = totalUsedArea3
case else
'do something or nothing
end select
Note that you have specified returning an integer which cannot contain a decimal and must be smaller than 32667 (or there abouts).
Here is my sphinx search configuration (sphinxsearch_0.9.9-6_amd64):
index FULL
{
charset_type = utf-8
source = FULL
path = /var/sphinx/data/Full
docinfo = extern
mlock = 0
min_stemming_len = 1
min_prefix_len = 1
min_word_len = 1
html_strip = 1
index_exact_words = 1
}
searchd
{
listen = 192.168.2.3
log = /var/log/sphinxsearch/searchd.log
query_log = /var/log/sphinxsearch/query.log
read_timeout = 3
client_timeout = 60
max_children = 30
pid_file = /var/run/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
mva_updates_pool = 1M
max_packet_size = 8M
max_filters = 256
max_filter_values = 4096
}
I use php as client
$sphinx_client->SetServer('localhost', 9312);
$sphinx_client->SetConnectTimeout(1);
$sphinx_client->SetArrayResult(true);
$sphinx_client->setRankingMode(SPH_RANK_WORDCOUNT);
$sphinx_client->SetMatchMode(SPH_MATCH_EXTENDED2);
if ($mode == 'all') {
$sphinx_client->SetSortMode(SPH_SORT_RELEVANCE, 'category');
} else {
$sphinx_client->setFilter('category', array($this->_filter_category), FALSE);
}
$sphinx_client->SetLimits(0, $this->_limit);
$results = $sphinx_client->Query('"^'.$query.'$"', 'FULL');
for example i have those names in index :
1. Alex
2. Alen
3. George
4. A
5. G
::: When i try to search for simple 1 char string "A" i get Alen / Alex / A and so on.
How can i search based on string length so i can display them in right order like :
A / Alen / Alex ...
I also get "WARNING: index 'FULL': no morphology, index_exact_words=1 has no effect, ignoring"
Best Regards
use an ordinal field ( str2ordinal ) , do your normal search , but modify sort mode : switch to extended mode and use a combination like $sphinx_client->SetSortMode(SPH_SORT_EXTENDED, '#weight desc , myordinal asc');