local-variables

Dynamic MySQL with local variables

心已入冬 提交于 2019-11-28 05:31:17
问题 How can I use dynamic SQL statements in MySQL database and without using session variables? Right now I have such a code (in MySQL stored procedure): (...) DECLARE TableName VARCHAR(32); SET @SelectedId = NULL; SET @s := CONCAT("SELECT Id INTO @SelectedId FROM ", TableName, " WHERE param=val LIMIT 1"); PREPARE stmt FROM @s; EXECUTE stmt; DEALLOCATE PREPARE stmt; IF ISNULL(@SelectedId) THEN (...) But I'd like to use only local variables, that means I'd like to start this procedure with:

Does an int in Objective-C have a default value of 1?

我的未来我决定 提交于 2019-11-28 04:16:29
问题 I have this simple line of code: int x; x automatically has the value of 1. I don't set it to anything but when I debug, it shows that x is 1. Does an int have a default value of 1?! 回答1: No. int has an undefined default value. It just happens to be 1 in this case. It could just as easily be -18382 or 22 or 0xBAADF00D . Always initialize your variables in C. 回答2: The initial value is undefined, and in this case will be whatever happened to be in that memory location before x started using it.

Declaring a useless local variable

[亡魂溺海] 提交于 2019-11-28 02:42:27
问题 So this is an odd one, I know the code itself is fairly useless, but what I'm wondering why I get the error: I was writing some code, I had written this: if(scan.hasNextInt()) int row = scan.nextInt(); Wasn't thinking about variable scope at the time, obviously this is useless because I can't use row past the if anyway. What I don't get is why I got the error I did: > javac hw.java hw.java:25: '.class' expected int row = scan.nextInt(); ^ hw.java:25: not a statement int row = scan.nextInt();

Where are .NET local variables stored?

試著忘記壹切 提交于 2019-11-27 23:39:12
In IL, you can define local variables using the .locals directive. Where are these variables stored, stack or heap? It is very much an implementation detail of the JIT compiler. It will try very hard to store local variables in a CPU register, very efficient. The stack is the usual backing store, in case there aren't enough registers available to store all the local variables. Big difference between the x86 and x64 jitters for example. x64 has a lot more registers available. This also applies to the arguments passed to a method. x86 allows 2 passed in a CPU register, x64 allows 4. Plus

access variables of outer class in Java

女生的网名这么多〃 提交于 2019-11-27 22:08:07
问题 in Java android application how can i access variables of outer class from the inner anonymous class ? Example: ProgressDialog dialog = new ProgressDialog(this); ..... send.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //here i'd like to do something with **dialog** variable ....... } }); 回答1: If the dialog variable is a field of the outer class, you can use this prefixed with the outer class name (a qualified this): send.setOnClickListener(new View

Dynamically set local variables in Ruby [duplicate]

狂风中的少年 提交于 2019-11-27 21:11:48
This question already has an answer here: How to dynamically create a local variable? 4 answers I'm interested in dynamically setting local variables in Ruby. Not creating methods, constants, or instance variables. So something like: args[:a] = 1 args.each_pair do |k,v| Object.make_instance_var k,v end puts a > 1 I want locally variables specifically because the method in question lives in a model and I dont want to pollute the global or object space. Dorkus Prime The problem here is that the block inside each_pair has a different scope. Any local variables assigned therein will only be

Undefine variable in Ruby

感情迁移 提交于 2019-11-27 19:58:38
Let's say I'm using irb , and type a = 5 . How do I remove the definition of a so that typing a returns a NameError ? Some context: later I want to do this: context = Proc.new{}.binding context.eval 'a = 5' context.eval 'undef a' # though this doesn't work. mikej There are remove_class_variable , remove_instance_variable and remove_const methods but there is currently no equivalent for local variables. You can avoid un-declaring the variable by reducing the scope in which the variable exists: def scope yield end scope do b = 1234 end b # undefined local variable or method `b' for main:Object

C++ local variable destruction order

馋奶兔 提交于 2019-11-27 19:35:35
Is there a defined order in which local variables are deallocated in C++ (11) ? To be more concise: In which order will side effects of the destructors of two local variables in the same scope become visible? e.g.: struct X{ ~X(){/*do something*/} } int main(){ X x1; X x2; return 0; } Is x1 or x2 destroyed first when main returns or is the order undefined in C++11? James Kanze Within each category of storage classes (except dynamically allocated objects), objects are destructed in the reverse order of construction. I. About local variables Local variables are allocated on the Stack . The Stack

In Ruby, why after starting irb, foo.nil? says undefined error, and @foo.nil? gives “true”, and @@wah.nil? gives error again?

旧时模样 提交于 2019-11-27 16:05:01
问题 Same in Ruby 1.8.7 and 1.9.2: $ irb ruby-1.8.7-p302 > foo.nil? NameError: undefined local variable or method `foo' for #<Object:0x3794c> from (irb):1 ruby-1.8.7-p302 > @bar.nil? => true ruby-1.8.7-p302 > @@wah.nil? NameError: uninitialized class variable @@wah in Object from (irb):3 why the instance variable treated differently than a local and class variable? 回答1: In Ruby, most uninitialized or even non-existing variables evaluate to nil . This is true for local variables, instance variables

Why does local variable kill my global variable?

試著忘記壹切 提交于 2019-11-27 14:29:24
问题 Sorry for this question, but this issue really screwed up my day. The following Code alerts 10 as it should: var globalId='10'; function check(){ alert(globalId); } check(); But this next code alerts undefined : var globalId='10'; function check(){ alert(globalId); var globalId; } check(); I am aware that if I declare a variable in a function its a local variable, but if I already declared it as global, how can it be that my alerts says undefined ? This is an easy example, but in my original