Search Results

Search found 7596 results on 304 pages for 'prepared statement'.

Page 10/304 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • SQL: Using a CASE Statement to update a 1000 rows at once, how??

    - by SoLoGHoST
    Ok, I would like to use a CASE STATEMENT for this, but I am lost with this. Basically, I need to update a ton of rows, but just on the "position" column. I need to update all "position" values from 0 - count(position) for each id_layout_position column per id_layout column. Here's what I got for a regular update, but I don't wanna throw this into a foreach loop, as it would take forever to do it. I'm using SMF (Simple Machines Forums), so it might look a little different, but the idea is the same, and CASE statements are supported... $smcFunc['db_query']('', ' UPDATE {db_prefix}dp_positions SET position = {int:position} WHERE id_layout_position = {int:id_layout_position} AND id_layout = {int:id_layout}', array( 'position' => $position++, 'id_layout_position' => (int) $id_layout_position, 'id_layout' => (int) $id_layout, ) ); Anyways, I need to apply some sort of CASE on this so that I can auto-increment by 1 all values that it finds and update to the next possible value. I know I'm doing this wrong, even in this QUERY. But I'm totally lost when it comes to CASES. Here's an example of a CASE being used within SMF, so you can see this and hopefully relate: $conditions = ''; foreach ($postgroups as $id => $min_posts) { $conditions .= ' WHEN posts >= ' . $min_posts . (!empty($lastMin) ? ' AND posts <= ' . $lastMin : '') . ' THEN ' . $id; $lastMin = $min_posts; } // A big fat CASE WHEN... END is faster than a zillion UPDATE's ;). $smcFunc['db_query']('', ' UPDATE {db_prefix}members SET id_post_group = CASE ' . $conditions . ' ELSE 0 END' . ($parameter1 != null ? ' WHERE ' . (is_array($parameter1) ? 'id_member IN ({array_int:members})' : 'id_member = {int:members}') : ''), array( 'members' => $parameter1, ) ); Before I do the update, I actually have a SELECT which throws everything I need into arrays like so: $disabled_sections = array(); $positions = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { if (!isset($disabled_sections[$row['id_group']][$row['id_layout']])) $disabled_sections[$row['id_group']][$row['id_layout']] = array( 'info' => $module_info[$name], 'id_layout_position' => $row['id_layout_position'] ); // Increment the positions... if (!is_null($row['position'])) { if (!isset($positions[$row['id_layout']][$row['id_layout_position']])) $positions[$row['id_layout']][$row['id_layout_position']] = 1; else $positions[$row['id_layout']][$row['id_layout_position']]++; } else $positions[$row['id_layout']][$row['id_layout_position']] = 0; } Thanks, I know if anyone can help me here it's definitely you guys and gals... Anyways, here is my question: How do I use a CASE statement in the first code example, so that I can update all of the rows in the position column from 0 - total # of rows found, that have that id_layout value and that id_layout_position value, and continue this for all different id_layout values in that table? Can I use the arrays above somehow? I'm sure I'll have to use the id_layout and id_layout_position values for this right? But how can I do this?

    Read the article

  • Can/Should you throw exceptions in a c# switch statement?

    - by Kettenbach
    Hi All, I have an insert query that returns an int. Based on that int I may wish to throw an exception. Is this appropriate to do within a switch statement? switch (result) { case D_USER_NOT_FOUND: throw new ClientException(string.Format("D User Name: {0} , was not found.", dTbx.Text)); case C_USER_NOT_FOUND: throw new ClientException(string.Format("C User Name: {0} , was not found.", cTbx.Text)); case D_USER_ALREADY_MAPPED: throw new ClientException(string.Format("D User Name: {0} , is already mapped.", dTbx.Text)); case C_USER_ALREADY_MAPPED: throw new ClientException(string.Format("C User Name: {0} , is already mapped.", cTbx.Text)); default: break; } I normally add break statements to switches but they will not be hit. Is this a bad design? Please share any opinions/suggestions with me. Thanks, ~ck in San Diego

    Read the article

  • How to create select SQL statement that would produce "merged" dataset from two tables(Oracle DBMS)?

    - by Roman Kagan
    Here's my original question: merging two data sets Unfortunately I omitted some intircacies, that I'd like to elaborate here. So I have two tables events_source_1 and events_source_2 tables. I have to produce the data set from those tables into resultant dataset (that I'd be able to insert into third table, but that's irrelevant). events_source_1 contain historic event data and I have to do get the most recent event (for such I'm doing the following: select event_type,b,c,max(event_date),null next_event_date from events_source_1 group by event_type,b,c,event_date,null events_source_2 contain the future event data and I have to do the following: select event_type,b,c,null event_date, next_event_date from events_source_2 where b>sysdate; How to put outer join statement to fill the void (i.e. when same event_type,b,c found from event_source_2 then next_event_date will be filled with the first date found GREATLY APPRECIATE FOR YOUR HELP IN ADVANCE.

    Read the article

  • Declare 2 types inside using statement gives compile error?

    - by citronas
    I want to use this line of code: using (ADataContext _dc = new ADataContext(ConnectionString), BDataContext _dc2 = new BrDataContext(ConnectionString)){ // ...} This gives a compile error: Cannot use more than one type in a for, using, fixed or declartion statement. I thought this was possible? MSDN says it is: http://msdn.microsoft.com/en-us/library/yh598w02%28VS.80%29.aspx In the MSDN sample code Font is used, which is class and thereby a reference type as well as my two DataContext classes. What went wrong here? How does my attempt differ from the MSDN sample?

    Read the article

  • C++ Long switch statement or look up with a map?

    - by Rachel
    In my C++ application, I have some values that act as codes to represent other values. To translate the codes, I've been debating between using a switch statement or an stl map. The switch would look something like this: int code; int value; switch(code) { case 1: value = 10; break; case 2: value = 15; break; } The map would be an stl::map<int, int> and translation would be a simple lookup with the code used as the key value. Which one is better/more efficient/cleaner/accepted? Why?

    Read the article

  • Is it bad practice to change state inside of an if statement?

    - by Benjamin
    I wrote some code that looks similar to the following: String SKIP_FIRST = "foo"; String SKIP_SECOND = "foo/bar"; int skipFooBarIndex(String[] list){ int index; if (list.length >= (index = 1) && list[0].equals(SKIP_FIRST) || list.length >= (index = 2) && (list[0] + "/" + list[1]).equals(SKIP_SECOND)){ return index; } return 0; } String[] myArray = "foo/bar/apples/peaches/cherries".split("/"); print(skipFooBarIndex(myArray); This changes state inside of the if statement by assigning index. However, my coworkers disliked this very much. Is this a harmful practice? Is there any reason to do it?

    Read the article

  • Why only the constant expression can be used as case expression in Switch statement?

    - by sinec
    Hi, what is bothering me is that I can't found an info regarding the question from the title. I found that assembly form the Switch-case statement is compiled into bunch of (MS VC 2008 compiler) cmp and je calls: 0041250C mov eax,dword ptr [i] 0041250F mov dword ptr [ebp-100h],eax 00412515 cmp dword ptr [ebp-100h],1 0041251C je wmain+52h (412532h) 0041251E cmp dword ptr [ebp-100h],2 00412525 je wmain+5Bh (41253Bh) 00412527 cmp dword ptr [ebp-100h],3 0041252E je wmain+64h (412544h) 00412530 jmp wmain+6Bh (41254Bh) where for above code will in case that if condition (i) is equal to 2, jump to address 41253Bh and do execution form there (at 41253Bh starts the code for 'case 2:' block) What I don't understand is why in case that,for instance, function is used as 'case expression', why first function couldn't be evaluated and then its result compared with the condition? Am I missing something? Thank you in advance

    Read the article

  • Is it a good idea to define a variable in a local block for a case of a switch statement?

    - by Paperflyer
    I have a rather long switch-case statement. Some of the cases are really short and trivial. A few are longer and need some variables that are never used anywhere else, like this: switch (action) { case kSimpleAction: // Do something simple break; case kComplexAction: { int specialVariable = 5; // Do something complex with specialVariable } break; } The alternative would be to declare that variable before going into the switch like this: int specialVariable = 5; switch (action) { case kSimpleAction: // Do something simple break; case kComplexAction: // Do something complex with specialVariable break; } This can get rather confusing since it is not clear to which case the variable belongs and it uses some unnecessary memory. However, I have never seen this usage anywhere else. Do you think it is a good idea to declare variables locally in a block for a single case?

    Read the article

  • Why "constructor-way" of declaring variable in "for-loop" allowed but in "if-statement" not allowed?

    - by PiotrNycz
    Consider this simple example: /*1*/ int main() { /*2*/ for (int i(7); i;){break;} /*3*/ if (int i(7)) {} /*4*/ } Why line-2 compiles just fine, whilst line-3 gives the error? This is little strange to me why if-statement is in this aspect treated worse than for-loop? If this is compiler specific - I tested with gcc-4.5.1: prog.cpp: In function 'int main()': prog.cpp:3:7: error: expected primary-expression before 'int' prog.cpp:3:7: error: expected ')' before 'int' I was inspired by this question [UPDATE] I know this compiles just fine: /*1*/ int main() { /*2*/ for (int i = 7; i;){break;} /*3*/ if (int i = 7) {} /*4*/ }

    Read the article

  • Generate a merge statement from table structure

    - by Nigel Rivett
    This code generates a merge statement joining on he natural key and checking all other columns to see if they have changed. The full version deals with type 2 processing and an audit trail but this version is useful. Just the insert or update part is handy too. Change the table at the top (spt_values in master in the version) and the join columns for the merge in @nk. The output generated is at the top and the code to run to generate it below. Output merge spt_values a using spt_values b on a.name = b.name and a.number = b.number and a.type = b.type when matched and (1=0 or (a.low b.low) or (a.low is null and b.low is not null) or (a.low is not null and b.low is null) or (a.high b.high) or (a.high is null and b.high is not null) or (a.high is not null and b.high is null) or (a.status b.status) or (a.status is null and b.status is not null) or (a.status is not null and b.status is null) ) then update set low = b.low , high = b.high , status = b.status when not matched by target then insert ( name , number , type , low , high , status ) values ( b.name , b.number , b.type , b.low , b.high , b.status ); Generator set nocount on declare @t varchar(128) = 'spt_values' declare @i int = 0 -- this is the natural key on the table used for the merge statement join declare @nk table (ColName varchar(128)) insert @nk select 'Number' insert @nk select 'Name' insert @nk select 'Type' declare @cols table (seq int, nkseq int, type int, colname varchar(128)) ;with cte as ( select ordinal_position, type = case when columnproperty(object_id(@t), COLUMN_NAME,'IsIdentity') = 1 then 3 when nk.ColName is not null then 1 else 0 end, COLUMN_NAME from information_schema.columns c left join @nk nk on c.column_name = nk.ColName where table_name = @t ) insert @cols (seq, nkseq, type, colname) select ordinal_position, row_number() over (partition by type order by ordinal_position) , type, COLUMN_NAME from cte declare @result table (i int, j int, k int, data varchar(500)) select @i = @i + 1 insert @result (i, data) select @i, 'merge ' + @t + ' a' select @i = @i + 1 insert @result (i, data) select @i, ' using cte b' select @i = @i + 1 insert @result (i, j, data) select @i, nkseq, ' ' + case when nkseq = 1 then 'on' else 'and' end + ' a.' + ColName + ' = b.' + ColName from @cols where type = 1 select @i = @i + 1 insert @result (i, data) select @i, ' when matched and (1=0' select @i = @i + 1 insert @result (i, j, k, data) select @i, seq, 1, ' or (a.' + ColName + ' b.' + ColName + ')' + ' or (a.' + ColName + ' is null and b.' + ColName + ' is not null)' + ' or (a.' + ColName + ' is not null and b.' + ColName + ' is null)' from @cols where type 1 select @i = @i + 1 insert @result (i, data) select @i, ' )' select @i = @i + 1 insert @result (i, data) select @i, ' then update set' select @i = @i + 1 insert @result (i, j, data) select @i, nkseq, ' ' + case when nkseq = 1 then ' ' else ', ' end + colname + ' = b.' + colname from @cols where type = 0 select @i = @i + 1 insert @result (i, data) select @i, ' when not matched by target then insert' select @i = @i + 1 insert @result (i, data) select @i, ' (' select @i = @i + 1 insert @result (i, j, data) select @i, seq, ' ' + case when seq = 1 then ' ' else ', ' end + colname from @cols where type 3 select @i = @i + 1 insert @result (i, data) select @i, ' )' select @i = @i + 1 insert @result (i, data) select @i, ' values' select @i = @i + 1 insert @result (i, data) select @i, ' (' select @i = @i + 1 insert @result (i, j, data) select @i, seq, ' ' + case when seq = 1 then ' ' else ', ' end + 'b.' + colname from @cols where type 3 select @i = @i + 1 insert @result (i, data) select @i, ' );' select data from @result order by i,j,k,data

    Read the article

  • PHP Prepared Statement Returns -1

    - by pws5068
    I've been using prepared statements for a little while now and I've never had any problems. Now I'm trying to: $sql="SELECT PhotoID,Caption FROM Photos WHERE EntityID=? AND TypeID=? LIMIT ?,?"; $iDB = new mysqliDB(); // Extends mysqli $stmt = $iDB->prepare($sql); $stmt->bind_param('iiii',$entityID,$typeID,$minRange,$maxRange); $stmt->execute(); $stmt->bind_result($photoID,$caption); echo("Affected={$stmt->affected_rows}"); This prints -1. I have triple tested that all 4 values in bindParam are set, and that the sql query works when pasted into myAdmin with the respective values. Any idea what may be causing this?

    Read the article

  • MySqli Prepared Statment Fetch Row

    - by pws5068
    I'm looking for an efficient way to select a specific row with a php prepared statement. $iDB = new mysqliDB(); $stmt = $iDB->prepare($sql); $stmt->bind_param('s',$searhStr); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($objID,$typeID,$year,$updated); // Now jump to row $rowNumber echo("Obj ID = {$objID}"); Any suggestions? Thanks!

    Read the article

  • MySQLi Prepared Statement Query Issue

    - by Benjamin Flak
    I'm relatively new to MySQLi prepared statements, and running into an error. Take this code: $user = 'admin'; $pass = 'admin'; if ($stmt = $mysqli->query("SELECT * FROM members WHERE username='$user' AND password='$pass'")) { echo $stmt->num_rows; } This will display "1", as it should. This next piece of code though, returns "0": $user = 'admin'; $pass = 'admin'; if ($stmt = $mysqli->prepare("SELECT * FROM members WHERE username=? AND password=?")) { $stmt->bind_param("ss", $user, $pass); $stmt->execute(); echo $stmt->num_rows; } Any ideas why?

    Read the article

  • Is it possible to write a Java printf statement that prints the statement itself?

    - by polygenelubricants
    Is it possible to have a Java printf statement, whose output is the statement itself? Some snippet to illustrate: // attempt #1 public class Main { public static void main(String[] args) { System.out.printf("something"); } } This prints something. So the output of attempt #1 is not quite exactly the printf statement in attempt #1. We can try something like this: // attempt #2 public class Main { public static void main(String[] args) { System.out.printf("System.out.printf(\"something\");"); } } And now the output is System.out.printf("something"); So now the output of attempt #2 matches the statement in output #1, but we're back to the problem we had before, since we need the output of attempt #2 to match the statement in attempt #2. So is it possible to write a one-line printf statement that prints itself?

    Read the article

  • inserting datetimes into database using java

    - by gordatron
    Hi, I am wanting to insert a datetime into a MySql data base using Java and a prepared statement: Calendar cal = Calendar.getInstance(); PreparedStatement stmnt = db.PreparedStatement("INSERT INTO Run " + "(Time) VALUE (?) "); stmnt.setDate(1, new java.sql.Date(cal.getTime())); stmnt.executeQuery(); NOTE: thre is currently an error - cannot find symbol (java.sql.Date) line 4 here db is an instance of a sort of wrapper class that exposes what I need from java.sql - its just getting a prepared statement from my connection object here. Time (the column) is a date time in my database, and I can only see sedDate and setTime method but I want to store both - also my code does not work anyway ;-) if anyone could give me some pointers on inserting a combined date time (current time would be a great help as that's my first goal) into a MySql DB using a prepared statement I would be very grateful. Thanks

    Read the article

  • Is there a more elegant solution than an if-statement with no else clause?

    - by Jay
    In the following code, if Control (the element that trigers Toggle's first OL) is not Visible it should be set Visible and all other Controls (Controls[i]) so be Hidden. .js function Toggle(Control){ var Controls=document.getElementsByTagName("ol",document.getElementById("Quote_App")); var Control=Control.getElementsByTagName("ol")[0]; if(Control.style.visibility!="visible"){ for(var i=0;i<Controls.length;i++){ if(Controls[i]!=Control){ Reveal("hide",20,0.3,Controls[i]); }else{ Reveal("show",20,0.3,Control); }; }; }else{ Reveal("hide",20,0.3,Control); }; }; Although the function [Toggle] works fine, it is actually setting Controls[i] to Hidden even if it is already. This is easily rectified by adding an If statement as in the code below, surely there is a more elegant solution, maybe a complex If condition? .js function Toggle(Control){ var Controls=document.getElementsByTagName("ol",document.getElementById("Quote_App")); var Control=Control.getElementsByTagName("ol")[0]; if(Control.style.visibility!="visible"){ for(var i=0;i<Controls.length;i++){ if(Controls[i]!=Control){ if(Controls[i].style.visibility=="visible"){ Reveal("hide",20,0.3,Controls[i]); }; }else{ Reveal("show",20,0.3,Control); }; }; }else{ Reveal("hide",20,0.3,Control); }; }; Your help is appreciated always.

    Read the article

  • C++: Simple data type for a variable in IF statement?

    - by Jason
    I am new to C++ and am making a simple text RPG, anyway, The scenario is I have a "welcome" screen with choices 1-3, and have a simple IF statement to check them, here: int choice; std::cout << "--> "; std::cin >> choice; if(choice == 1) { //.. That works fine, but if someone enters a letter as selection (instead of 1, 2 or 3) it'll become "-392493492"or something and crash the program. So I came up with: char choice; std::cout << "--> "; std::cin >> choice; if(choice == 1) { //.. This works kinda fine, but when I enter a number it seems to skip the IF statements completely.. Is the char "1" the same as the number 1? I get a compiler errro with this (ISO-CPP or something): if(choice == "1") So how on earth do I see if they entered 1-3 correctly!?

    Read the article

  • SQL03070: This statement is not recognized in this context

    - by prash
    Recently I have started working with VS2010 and Fx4. There have been various challenges. We also introduced a new Database Project in our solution. And found this error. The reason for this error is: the project system expects the stored procedure as a create statement only.  The additional statements to drop if existing are not necessary within the project system.  Project deployment takes care of detecting if the sproc already exists and if it needs to be updated. To resolve this error you can simply remove the additional statements other then your create SP, Function etc. OR Exclude the file from build. Right Click on your file in Solution Explorer, Click Properties > Build Action > Not in Build

    Read the article

  • Missing return statement when using .charAt [migrated]

    - by Timothy Butters
    I need to write a code that returns the number of vowels in a word, I keep getting an error in my code asking for a missing return statement. Any solutions please? :3 import java.util.*; public class vowels { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Please type your name."); String name = input.nextLine(); System.out.println("Congratulations, your name has "+ countVowels(name) +" vowels."); } public static int countVowels(String str) { int count = 0; for (int i=0; i < str.length(); i++) { // char c = str.charAt(i); if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'o' || str.charAt(i) == 'i' || str.charAt(i) == 'u') count = count + 1; } } }

    Read the article

  • If-else statement comments [closed]

    - by Jin35
    Possible Duplicate: What is a good way to comment if-else-clauses? What is the best way to write comments for if-else statement? There is possible ways: A. //first comment if (condition) { ... } //second comment else { ... } B. if (condition) { //first comment ... } else { //second comment ... } C. if (condition) { //first comment ... } else { //second comment ... } Which one is the best, or there is some better possibilities?

    Read the article

  • Ruby: if statement using regexp and boolean operator [migrated]

    - by bev
    I'm learning Ruby and have failed to make a compound 'if' statement work. Here's my code (hopefully self explanatory) commentline = Regexp.new('^;;') blankline = Regexp.new('^(\s*)$') if (line !~ commentline || line !~ blankline) puts line end the variable 'line' is gotten from reading the following file: ;; alias filename backupDir Prog_i Prog_i.rb ./store Prog_ii Prog_ii.rb ./store This fails and I'm not sure why. Basically I want the comment lines and blank lines to be ignored during the processing of the lines in the file. Thanks for your help.

    Read the article

  • Unit testing multiple conditions in an IF statement

    - by bwalk2895
    I have a chunk of code that looks something like this: function bool PassesBusinessRules() { bool meetsBusinessRules = false; if (PassesBusinessRule1 && PassesBusinessRule2 && PassesBusinessRule3) { meetsBusinessRules= true; } return meetsBusinessRules; } I believe there should be four unit tests for this particular function. Three to test each of the conditions in the if statement and ensure it returns false. And another test that makes sure the function returns true. Question: Should there actually be ten unit tests instead? Nine that checks each of the possible failure paths. IE: False False False False False True False True False And so on for each possible combination. I think that is overkill, but some of the other members on my team do not. The way I look at it is if BusinessRule1 fails then it should always return false, it doesn't matter if it was checked first or last.

    Read the article

  • Why does my if statement always evaluate to true?

    - by Pobe
    I need to go through the months of the year and find out if the last day of the month is 28, 29, 30 or 31. My problem is that the first if statement always evaluates to true: MOIS_I = 31 if (mois == "Janvier" || "Mars" || "Mai" || "Juillet" || "Août" || "Octobre" || "Décembre" || "1" || "3" || "5" || "7" || "8" || "10" || "12" || "01" || "03" || "05" || "07" || "08") { window.alert("Le mois " + mois + " de l'année " + annee + " compte " + MOIS_I + " jours "); } Also, it seems like it is necessary to do if (mois == "Janver" || mois == "Février" || ... ) and so on, but I wanted to know if there was a better way to do it. Here is the full code: var mois, annee, test4, test100, test400; const MOIS_P = 30; const MOIS_I = 31; const FEV_NORM = 28; const FEV_BISSEX = 29; const TEST_4 = 4; const TEST_100 = 100; const TEST_400 = 400; mois = window.prompt("Entrez un mois de l'année", ""); annee = window.prompt("Entrez l'année de ce mois", ""); /* MOIS IMPAIRS */ if (mois == "Janvier" || "Mars" || "Mai" || "Juillet" || "Août" || "Octobre" || "Décembre" || "1" || "3" || "5" || "7" || "8" || "10" || "12" || "01" || "03" || "05" || "07" || "08") { window.alert("Le mois " + mois + " de l'année " + annee + " compte " + MOIS_I + " jours "); /* MOIS PAIRS */ } else if (mois == "Février" || "Avril" || "Juin" || "Septembre" || "Novembre" || "2" || "4" || "6" || "9" || "11" || "02" || "04" || "06" || "09") { if (mois == "Février") { test4 = parseInt(annee) % TEST_4; test100 = parseInt(annee) % TEST_100; test400 = parseInt(annee) % TEST_400; if (test4 == 0) { if (test100 != 0) { window.alert("Le mois " + mois + " de l'année " + annee + " compte " + FEV_BISSEX + " jours "); } else { window.alert("Le mois " + mois + " de l'année " + annee + " compte " + FEV_NORM + " jours "); } } else if (test400 == 0) { window.alert("Le mois " + mois + " de l'année " + annee + " compte " + FEV_BISSEX + " jours "); } else { window.alert("Le mois " + mois + " de l'année " + annee + " compte " + FEV_NORM + " jours "); } } else { window.alert("Le mois " + mois + " de l'année " + annee + " compte " + MOIS_P + " jours "); } } else { window.alert("Apocalypse!"); } TEST_4, TEST_100, TEST_400 are to test if the year is a leap year (which means february has 29 days instead of 28). Thank you!

    Read the article

  • Behavior of local variables in JavaScripts with()-statement

    - by thr
    I noticed some weird (and to my knowledge undefined behavior, by the ECMA 3.0 Spec at least), take the following snippet: var foo = { bar: "1", baz: "2" }; alert(bar); with(foo) { alert(bar); alert(bar); } alert(bar); It crashes in both Firefox and Chrome, because "bar" doesn't exist in the first alert(); statement, this is as expected. But if you add a declaration of bar inside the with()-statement, so it looks like this: var foo = { bar: "1", baz: "2" }; alert(bar); with(foo) { alert(bar); var bar = "g2"; alert(bar); } alert(bar); It will produce the following: undefined, 1, g2, undefined It seems as if you create a variable inside a with()-statement most browsers (tested on Chrome or Firefox) will make that variable exist outside that scope also, it's just set to undefined. Now from my perspective bar should only exist inside the with()-statement, and if you make the example even weirder: var foo = { bar: "1", baz: "2" }; var zoo; alert(bar); with(foo) { alert(bar); var bar = "g2"; zoo = function() { return bar; } alert(bar); } alert(bar); alert(zoo()); It will produce this: undefined, 1, g2, undefined, g2 So the bar inside the with()-statement does not exist outside of it, yet the runtime somehow "automagically" creates a variable named bar that is undefined in its top level scope (global or function) but this variable does not refer to the same one as inside the with()-statement, and that variable will only exist if a with()-statement has a variable named bar that is defined inside it. Very weird, and inconsistent. Anyone have an explanation for this behavior? There is nothing in the ECMA Spec about this.

    Read the article

  • LEMP Stack on Ubuntu Server 13.04 not parsing PHP Switch Statement Properly

    - by schester
    On my Ubuntu 12.04 Server LTS on nginx 1.1.19, the following PHP code works properly: switch($_SESSION['user']['permissions']) { case 9: echo "Super Admin Privileges"; break; case 0: echo "Operator Privileges"; break; case 1: echo "Line Leader Privileges"; break; case 2: echo "Supervisor Privileges"; break; case 3: echo "Engineer Privileges"; break; case 4: echo "Manager Privileges"; break; case 5: echo "Administrator Privileges"; break; default: echo "Operator Privileges"; } However, I have a backup server running Ubuntu Server 13.04 on nginx 1.4.1 which has the exact same copy of the script (synced) but instead of breaking on the break; command, it echos the whole php script. The output on the 12.04 Box is similar to this: You are logged in with Super Admin Privileges But on the 13.04 Box, the output is like this: You are logged in logged in with Super Admin Privileges"; break; case 0: echo "Operator Privileges"; break; case 1: echo "Line Leader Privileges"; break; case 2: echo "Supervisor Privileges"; break; case 3: echo "Engineer Privileges"; break; case 4: echo "Manager Privileges"; break; case 5: echo "Administrator Privileges"; break; default: echo "Operator Privileges"; } ?> I have also tried changing the script from switch statement to if statements but same results. Any idea what is wrong?

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >