conditional-statements

Rails 2.3.5 Problem Building Conditions Array dynamically when using in (?)

不问归期 提交于 2019-12-10 18:51:30
问题 Rails 2.3.5 I've looked at a number of other questions relating to building conditions dynamically for an ActiveRecord find. I'm aware there are some great gems out there like search logic and that this is better in Rails3. However, I'm using geokit for geospacial search and I'm trying to build just a standard conditions set that will allow me to combine a slew of different filters. I have 12 different filters that I'm trying to combine dynamically for an advanced search. I need to be able to

If statement with && where the first condition needs to be true before testing the second [duplicate]

不问归期 提交于 2019-12-10 18:30:00
问题 This question already has answers here : && (AND) and || (OR) in IF statements (9 answers) Closed 6 years ago . Sorry if this is a duplicate, but I can't even think of a way to search of this. I'm not sure of the terminology to ask the question, so I'll just walk through my problem. From my tests, it seems the if statement will quit before attempting to go to go to array[10]. I that always the case? Meaning, if I have an && in my if statement and the left side is false, will it always exit

Adding more than one condition in Projection.Conditionals for queryover

浪子不回头ぞ 提交于 2019-12-10 18:06:48
问题 I am trying to write a case with more than one when clause; something like this: ... case when 'starks' then 1 when 'wildlings' then 2 when 'lannisters' then 3 Else 0 End ... I've done a single conditional before with something like .OrderBy(Projections.Conditional( Restrictions.Where<House>(r => r.Name.IsLike("starks")), Projections.Constant(0), Projections.Constant(1))).Asc(); But I can't figure out how to add an extra condition / when clause in there :/ I've tried adding an extra outer

WIX. How to not reinstall a feature during repair?

廉价感情. 提交于 2019-12-10 17:51:06
问题 In WIX I'd like a feature to be installed and uninstalled normally but not to be touched during repair. I was not able to find a condition which would allow me to do this. My attempts has failed: the feature is reinstalled on repair (what I do not need) or is not uninstalled. This is a sample that I tried last: <Feature Id="aFeature" Title="A Features" Level="1"> <ComponentRef Id="aComponent" /> <Condition Level="0"> <![CDATA[WixUI_InstallMode="Repair"]]> </Condition> </Feature> What is the

.Net 3.5 Implementation of String.IsNullOrWhitespace with Code Contracts

我们两清 提交于 2019-12-10 17:34:52
问题 I'm attempting to use Contracts in my .Net 3.5 (C#) project. I found where I had written something like if (string.IsNullOrEmpty(s) || string.IsNullOrEmpty(s.Trim())) throw new ArgumentException("Required", "s"); at the beginning of methods. I could keep them there and use legacy contracts. I could change it to Contract.Requires(s!= null && string.IsNullOrEmpty(s.Trim())); . But besides not being very sure about the correctness or performance of the Whitespace part of the condition, those are

What is the most pythonic way to conditionally return a function

自闭症网瘾萝莉.ら 提交于 2019-12-10 17:25:08
问题 Say I have 2 functions. I want func2 to return func1 UNLESS func1 returns None, in which case func2 returns something else. There are two ways that I could do this, but they both feel slightly wrong. I could say: def func1(n): if (condition): return foo def func2(n): if func1(n) is not None: return func1(n) else: return something_else But this feels wrong because I have to call func1(n) twice (and func1(n) is a larger computation). To get around that, I could say: def func1(n): if (condition)

Dynamic conditions in WHERE clause

守給你的承諾、 提交于 2019-12-10 16:38:55
问题 I have a stored procedure and would like to know if its possible to build up a dynamic where condition based on a parameter. Lets say I have this query: SELECT * FROM tbl_Users Now, I have a parameter called @username , which I would like to use to build up a dynamic where condition (which through my program might be 1 or more conditions). To achieve something like that I use the following statement: SELECT * FROM tbl_Users @username -- where this parameter might hold a condition string such

Django template if statement always evaluates to true

跟風遠走 提交于 2019-12-10 16:21:15
问题 This seems like it should be pretty straightforward, but for some reason I am unable to solve this problem. I'm using Django 1.4. I am trying to do a basic check to see if a list QuerySet is empty or not during template rendering, but the if statement I'm using seems always to evaluate to true. I have a Django template that reads: {% extends 'includes/base.html' %} {% if object_list %} ... {% block data %} {% for object in object_list %} ... {{ object.create_date }} ... {% endfor %} {%

sql count/sum the number of calls until a specific date in another column

邮差的信 提交于 2019-12-10 15:39:34
问题 I have data that shows the customer calls. I have columns for customer number, phone number(1 customer can have many), date record for each voice call and duration of a call. Table looks lie below example. CusID | PhoneNum | Date | Duration 20111 43576233 20.01.2016-14:00 00:10:12 20111 44498228 14.01.2016-15:30 00:05:12 20112 43898983 14.01.2016-15:30 What I want is to count the number of call attempts for each number before It is answered(Duration is > 0). So that I can estimate how many

Using a scalar as a condition in perl

 ̄綄美尐妖づ 提交于 2019-12-10 14:39:19
问题 First timer...so let me know if there is anything that I have not paid attention to whilst posing a question. The question is how to use a scalar as a condition, as the code below does not work. my @parameter=('hub'); my %condition; $condition{'hub'}{'1'}='$degree>=5'; foreach (@parameter) { if ($condition{$_}{'1'}) {..} } I thought that is because the condition is not interpreted correctly, so I also tried the following, which also did not work. if ("$condition{$parameter}{'1'}") { ..} Would