Search Results

Search found 2240 results on 90 pages for 'assert redirected to'.

Page 1/90 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Operator of the week - Assert

    - by Fabiano Amorim
    Well my friends, I was wondering how to help you in a practical way to understand execution plans. So I think I'll talk about the Showplan Operators. Showplan Operators are used by the Query Optimizer (QO) to build the query plan in order to perform a specified operation. A query plan will consist of many physical operators. The Query Optimizer uses a simple language that represents each physical operation by an operator, and each operator is represented in the graphical execution plan by an icon. I'll try to talk about one operator every week, but so as to avoid having to continue to write about these operators for years, I'll mention only of those that are more common: The first being the Assert. The Assert is used to verify a certain condition, it validates a Constraint on every row to ensure that the condition was met. If, for example, our DDL includes a check constraint which specifies only two valid values for a column, the Assert will, for every row, validate the value passed to the column to ensure that input is consistent with the check constraint. Assert  and Check Constraints: Let's see where the SQL Server uses that information in practice. Take the following T-SQL: IF OBJECT_ID('Tab1') IS NOT NULL   DROP TABLE Tab1 GO CREATE TABLE Tab1(ID Integer, Gender CHAR(1))  GO  ALTER TABLE TAB1 ADD CONSTRAINT ck_Gender_M_F CHECK(Gender IN('M','F'))  GO INSERT INTO Tab1(ID, Gender) VALUES(1,'X') GO To the command above the SQL Server has generated the following execution plan: As we can see, the execution plan uses the Assert operator to check that the inserted value doesn't violate the Check Constraint. In this specific case, the Assert applies the rule, 'if the value is different to "F" and different to "M" than return 0 otherwise returns NULL'. The Assert operator is programmed to show an error if the returned value is not NULL; in other words, the returned value is not a "M" or "F". Assert checking Foreign Keys Now let's take a look at an example where the Assert is used to validate a foreign key constraint. Suppose we have this  query: ALTER TABLE Tab1 ADD ID_Genders INT GO  IF OBJECT_ID('Tab2') IS NOT NULL   DROP TABLE Tab2 GO CREATE TABLE Tab2(ID Integer PRIMARY KEY, Gender CHAR(1))  GO  INSERT INTO Tab2(ID, Gender) VALUES(1, 'F') INSERT INTO Tab2(ID, Gender) VALUES(2, 'M') INSERT INTO Tab2(ID, Gender) VALUES(3, 'N') GO  ALTER TABLE Tab1 ADD CONSTRAINT fk_Tab2 FOREIGN KEY (ID_Genders) REFERENCES Tab2(ID) GO  INSERT INTO Tab1(ID, ID_Genders, Gender) VALUES(1, 4, 'X') Let's look at the text execution plan to see what these Assert operators were doing. To see the text execution plan just execute SET SHOWPLAN_TEXT ON before run the insert command. |--Assert(WHERE:(CASE WHEN NOT [Pass1008] AND [Expr1007] IS NULL THEN (0) ELSE NULL END))      |--Nested Loops(Left Semi Join, PASSTHRU:([Tab1].[ID_Genders] IS NULL), OUTER REFERENCES:([Tab1].[ID_Genders]), DEFINE:([Expr1007] = [PROBE VALUE]))           |--Assert(WHERE:(CASE WHEN [Tab1].[Gender]<>'F' AND [Tab1].[Gender]<>'M' THEN (0) ELSE NULL END))           |    |--Clustered Index Insert(OBJECT:([Tab1].[PK]), SET:([Tab1].[ID] = RaiseIfNullInsert([@1]),[Tab1].[ID_Genders] = [@2],[Tab1].[Gender] = [Expr1003]), DEFINE:([Expr1003]=CONVERT_IMPLICIT(char(1),[@3],0)))           |--Clustered Index Seek(OBJECT:([Tab2].[PK]), SEEK:([Tab2].[ID]=[Tab1].[ID_Genders]) ORDERED FORWARD) Here we can see the Assert operator twice, first (looking down to up in the text plan and the right to left in the graphical plan) validating the Check Constraint. The same concept showed above is used, if the exit value is "0" than keep running the query, but if NULL is returned shows an exception. The second Assert is validating the result of the Tab1 and Tab2 join. It is interesting to see the "[Expr1007] IS NULL". To understand that you need to know what this Expr1007 is, look at the Probe Value (green text) in the text plan and you will see that it is the result of the join. If the value passed to the INSERT at the column ID_Gender exists in the table Tab2, then that probe will return the join value; otherwise it will return NULL. So the Assert is checking the value of the search at the Tab2; if the value that is passed to the INSERT is not found  then Assert will show one exception. If the value passed to the column ID_Genders is NULL than the SQL can't show a exception, in that case it returns "0" and keeps running the query. If you run the INSERT above, the SQL will show an exception because of the "X" value, but if you change the "X" to "F" and run again, it will show an exception because of the value "4". If you change the value "4" to NULL, 1, 2 or 3 the insert will be executed without any error. Assert checking a SubQuery: The Assert operator is also used to check one subquery. As we know, one scalar subquery can't validly return more than one value: Sometimes, however, a  mistake happens, and a subquery attempts to return more than one value . Here the Assert comes into play by validating the condition that a scalar subquery returns just one value. Take the following query: INSERT INTO Tab1(ID_TipoSexo, Sexo) VALUES((SELECT ID_TipoSexo FROM Tab1), 'F')    INSERT INTO Tab1(ID_TipoSexo, Sexo) VALUES((SELECT ID_TipoSexo FROM Tab1), 'F')    |--Assert(WHERE:(CASE WHEN NOT [Pass1016] AND [Expr1015] IS NULL THEN (0) ELSE NULL END))        |--Nested Loops(Left Semi Join, PASSTHRU:([tempdb].[dbo].[Tab1].[ID_TipoSexo] IS NULL), OUTER REFERENCES:([tempdb].[dbo].[Tab1].[ID_TipoSexo]), DEFINE:([Expr1015] = [PROBE VALUE]))              |--Assert(WHERE:([Expr1017]))             |    |--Compute Scalar(DEFINE:([Expr1017]=CASE WHEN [tempdb].[dbo].[Tab1].[Sexo]<>'F' AND [tempdb].[dbo].[Tab1].[Sexo]<>'M' THEN (0) ELSE NULL END))              |         |--Clustered Index Insert(OBJECT:([tempdb].[dbo].[Tab1].[PK__Tab1__3214EC277097A3C8]), SET:([tempdb].[dbo].[Tab1].[ID_TipoSexo] = [Expr1008],[tempdb].[dbo].[Tab1].[Sexo] = [Expr1009],[tempdb].[dbo].[Tab1].[ID] = [Expr1003]))              |              |--Top(TOP EXPRESSION:((1)))              |                   |--Compute Scalar(DEFINE:([Expr1008]=[Expr1014], [Expr1009]='F'))              |                        |--Nested Loops(Left Outer Join)              |                             |--Compute Scalar(DEFINE:([Expr1003]=getidentity((1856985942),(2),NULL)))              |                             |    |--Constant Scan              |                             |--Assert(WHERE:(CASE WHEN [Expr1013]>(1) THEN (0) ELSE NULL END))              |                                  |--Stream Aggregate(DEFINE:([Expr1013]=Count(*), [Expr1014]=ANY([tempdb].[dbo].[Tab1].[ID_TipoSexo])))             |                                       |--Clustered Index Scan(OBJECT:([tempdb].[dbo].[Tab1].[PK__Tab1__3214EC277097A3C8]))              |--Clustered Index Seek(OBJECT:([tempdb].[dbo].[Tab2].[PK__Tab2__3214EC27755C58E5]), SEEK:([tempdb].[dbo].[Tab2].[ID]=[tempdb].[dbo].[Tab1].[ID_TipoSexo]) ORDERED FORWARD)  You can see from this text showplan that SQL Server as generated a Stream Aggregate to count how many rows the SubQuery will return, This value is then passed to the Assert which then does its job by checking its validity. Is very interesting to see that  the Query Optimizer is smart enough be able to avoid using assert operators when they are not necessary. For instance: INSERT INTO Tab1(ID_TipoSexo, Sexo) VALUES((SELECT ID_TipoSexo FROM Tab1 WHERE ID = 1), 'F') INSERT INTO Tab1(ID_TipoSexo, Sexo) VALUES((SELECT TOP 1 ID_TipoSexo FROM Tab1), 'F')  For both these INSERTs, the Query Optimiser is smart enough to know that only one row will ever be returned, so there is no need to use the Assert. Well, that's all folks, I see you next week with more "Operators". Cheers, Fabiano

    Read the article

  • Boost 1.4.0, "assert" identifier not found

    - by Adam Haile
    I'm trying to compile an old project that was originally written for linux on windows. It uses boost 1.4.0, and whenever I compile it throws error C3961: "assert" : identifier not found. I'm using Visual Studio 208 SP1 When I drill down into assert.hpp it includes this: # include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same # define BOOST_ASSERT(expr) assert(expr) BOOST_ASSERT is actually what's failing, and VS doesn't seem to recognize assert() even though assert.h is obviously included. As far as I can tell, all the fails are in files that are part of boost, not my own code, but it throws about 1200 of them. Any ideas how to fix this?

    Read the article

  • Assert a good practice or not ?

    - by rkenshin
    Is it a good practice to use Assert for function parameters to enforce their validity. I was going through the source code of Spring Framework and I noticed that they use Assert.notNull a lot. Here's an example public static ParsedSql parseSqlStatement(String sql) { Assert.notNull(sql, "SQL must not be null");} Here's Another one public NamedParameterJdbcTemplate(DataSource dataSource) { Assert.notNull(dataSource, "The [dataSource] argument cannot be null."); this .classicJdbcTemplate = new JdbcTemplate(dataSource); } public NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate) { Assert.notNull(classicJdbcTemplate, "JdbcTemplate must not be null"); this .classicJdbcTemplate = classicJdbcTemplate; } Thank you

    Read the article

  • Slow Scala assert

    - by Dave
    We've been profiling our code recently and we've come across a few annoying hotspots. They're in the form assert(a == b, a + " is not equal to " + b) Because some of these asserts can be in code called a huge amount of times the string concat starts to add up. assert is defined as: def assert(assumption : Boolean, message : Any) = .... why isn't it defined as: def assert(assumption : Boolean, message : => Any) = .... That way it would evaluate lazily. Given that it's not defined that way is there an inline way of calling assert with a message param that is evaluated lazily? Thanks

    Read the article

  • What is default javac source mode (assert as identifier compilation)?

    - by waste
    According to Orcale's Java7 assert guide: source mode 1.3 (default) — the compiler accepts programs that use assert as an identifier, but issues warnings. In this mode, programs are not permitted to use the assert statement. source mode 1.4 — the compiler generates an error message if the program uses assert as an identifier. In this mode, programs are permitted to use the assert statement. I wrote such class: package mm; public class ClassTest { public static void main(String[] arg) { int assert = 1; System.out.println(assert); } } It should compile fine if Oracle's info right (1.3 is default source mode). But I got errors like this: $ javac -version javac 1.7.0_04 $ javac -d bin src/mm/* src\mm\ClassTest.java:5: error: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier int assert = 1; ^ (use -source 1.3 or lower to use 'assert' as an identifier) src\mm\ClassTest.java:6: error: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier System.out.println(assert); ^ (use -source 1.3 or lower to use 'assert' as an identifier) 2 errors I added manually -source 1.3 and it issued warnings but compiled fine. It seems that Oracle's information is wrong and 1.3 is not default source mode. Which one is it then?

    Read the article

  • If as assert fails, is there a bug?

    - by RichAmberale
    I've always followed the logic: if assert fails, then there is a bug. Root cause could either be: Assert itself is invalid (bug) There is a programming error (bug) (no other options) I.E. Are there any other conclusions one could come to? Are there cases where an assert would fail and there is no bug?

    Read the article

  • [NUnit+Moq] Guidelines for using Assert versus Verify

    - by emddudley
    I'm new to unit testing, and I'm learning how to use NUnit and Moq. NUnit provides Assert syntax for testing conditions in my unit tests, while Moq provides some Verify functions. To some extent these seem to provide the same functionality. How do I know when it's more appropriate to use Assert or Verify? Maybe Assert is better for confirming state, and Verify is better for confirming behavior (Classical versus Mockist)?

    Read the article

  • php numbers: assert( 1.0 < 2.0 )

    - by xtofl
    How can this <?php assert( 1.0 < 2.0 ); ?> result in Warning: assert() [function.assert]: Assertion failed in C:\Program Files (x86)\wamp\www\test.php on line 2 Edit: depending on the file I put this code in, 1.0 < 2.0 evaluates to false or true.

    Read the article

  • Debug.Assert replacement for Phone and Store apps

    - by Daniel Moth
    I don’t know about you, but all my code is, and always has been, littered with Debug.Assert statements. I think it all started way back in my (short-lived, but impactful to me) Eiffel days, when I was applying Design by Contract. Anyway, I can’t live without Debug.Assert. Imagine my dismay when I upgraded my Windows Phone 7.x app (Translator By Moth) to Windows Phone 8 and discovered that my Debug.Assert statements would not display anything on the target and would not break in the debugger any longer! Luckily, the solution was simple and in this post I share it with you – feel free to teak it to meet your needs. Steps to use Add a new code file to your project, delete all its contents, and paste in the code from MyDebug.cs Perform a global search in your solution replacing Debug.Assert with MyDebug.Assert Build solution and test Now, I do not know why this functionality was broken, but I do know that it exhibits the same broken characteristics for Windows Store apps. There is a simple workaround there to use Contract.Assert which does display a message and offers an option to break in the debugger (although it doesn’t output the message to the Output window). Because I plan on code sharing between Phone and Windows 8 projects, I prefer to have the conditional compilation centralized, so I added the Contract.Assert workaround directly in MyDebug class, so that you can use this class for both platforms – enjoy and enhance! Comments about this post by Daniel Moth welcome at the original blog.

    Read the article

  • IOKit header assert.h gone? [answered]

    - by Julian Kessel
    I want to get the hardware address of my mac's ethernet card. In all samples I saw in include on IOKit/assert.h . Which doesn't seem to exist on my system. GCC throws an error saying he doesn't know the type IOEthernetAddress. Is assert.h necessary for my task? It would be great if someone coud give me a working sample. [edit] here's my code, think this will help understanding the problem: #include <IOKit/assert.h> #include <IOKit/network/IOEthernetController.h> #include <IOKit/network/IOEthernetInterface.h> int main(){ IOEthernetAddress addr; getHardwareAddress(&addr); printf("%x", addr); return 0; }

    Read the article

  • Best practice for Python Assert

    - by meade
    Is there a performance or code maintenance issue with using assert as part of the standard code instead of using it just for debugging purposes? Is assert x >= 0, 'x is less then zero' and better or worse then if x < 0: raise Exception, 'x is less then zero' Also, is there anyway to set a business rule like if x < 0 raise error that is always checked with out the try, except, finally so, if at anytime throughout the code x is < 0 an error is raised, like if you set assert x < 0 at the start of a function, anywhere within the function where x becomes less then 0 an exception is raised?

    Read the article

  • Usage of Assert.Inconclusive

    - by Johannes Rudolph
    Hi, Im wondering how someone should use Assert.Inconclusive(). I'm using it if my Unit test would be about to fail for a reason other than what it is for. E.g. i have a method on a class that calculates the sum of an array of ints. On the same class there is also a method to calculate the average of the element. It is implemented by calling sum and dividing it by the length of the array. Writing a Unit test for Sum() is simple. However, when i write a test for Average() and Sum() fails, Average() is likely to fail also. The failure of Average is not explicit about the reason it failed, it failed for a reason other than what it should test for. That's why i would check if Sum() returns the correct result, otherwise i Assert.Inconclusive(). Is this to be considered good practice? What is Assert.Inconclusive intended for? Or should i rather solve the previous example by means of an Isolation Framework?

    Read the article

  • Java assert nasty side-effect - compiler bug?

    - by Alex
    This public class test { public static void main(String[] args) { Object o = null; assert o != null; if(o != null) System.out.println("o != null"); } } prints out "o != null"; both 1.5_22 and 1.6_18. Compiler bug? Commenting out the assert fixes it. The byte code appears to jump directly to the print statement when assertions are disabled: public static main(String[]) : void L0 LINENUMBER 5 L0 ACONST_NULL ASTORE 1 L1 LINENUMBER 6 L1 GETSTATIC test.$assertionsDisabled : boolean IFNE L2 ALOAD 1: o IFNONNULL L2 NEW AssertionError DUP INVOKESPECIAL AssertionError.<init>() : void ATHROW L2 LINENUMBER 8 L2 GETSTATIC System.out : PrintStream LDC "o != null" INVOKEVIRTUAL PrintStream.println(String) : void L3 LINENUMBER 9 L3 RETURN L4

    Read the article

  • Is Java assert broken?

    - by BlairHippo
    While poking around the questions, I recently discovered the assert keyword in Java. At first, I was excited. Something useful I didn't already know! A more efficient way for me to check the validity of input parameters! Yay learning! But then I took a closer look, and my enthusiasm was not so much "tempered" as "snuffed-out completely" by one simple fact: you can turn assertions off.* This sounds like a nightmare. If I'm asserting that I don't want the code to keep going if the input listOfStuff is null, why on earth would I want that assertion ignored? It sounds like if I'm debugging a piece of production code and suspect that listOfStuff may have been erroneously passed a null but don't see any logfile evidence of that assertion being triggered, I can't trust that listOfStuff actually got sent a valid value; I also have to account for the possibility that assertions may have been turned off entirely. And this assumes that I'm the one debugging the code. Somebody unfamiliar with assertions might see that and assume (quite reasonably) that if the assertion message doesn't appear in the log, listOfStuff couldn't be the problem. If your first encounter with assert was in the wild, would it even occur to you that it could be turned-off entirely? It's not like there's a command-line option that lets you disable try/catch blocks, after all. All of which brings me to my question (and this is a question, not an excuse for a rant! I promise!): What am I missing? Is there some nuance that renders Java's implementation of assert far more useful than I'm giving it credit for? Is the ability to enable/disable it from the command line actually incredibly valuable in some contexts? Am I misconceptualizing it somehow when I envision using it in production code in lieu of statements like if (listOfStuff == null) barf();? I just feel like there's something important here that I'm not getting. *Okay, technically speaking, they're actually off by default; you have to go out of your way to turn them on. But still, you can knock them out entirely.

    Read the article

  • Using Assert to compare two objects

    - by baron
    Hi everyone, Writing test cases for my project, one test I need is to test deletion. This may not exactly be the right way to go about it, but I've stumbled upon something which isn't making sense to me. Code is like this: [Test] private void DeleteFruit() { BuildTestData(); var f1 = new Fruit("Banana",1,1.5); var f2 = new Fruit("Apple",1,1.5); fm.DeleteFruit(f1,listOfFruit); Assert.That(listOfFruit[1] == f2); } Now the fruit object I create line 5 is the object that I know should be in that position (with this specific dataset) after f1 is deleted. Also if I sit and debug, and manually compare objects listOfFruit[1] and f2 they are the same. But that Assert line fails. What gives?

    Read the article

  • IOKit header assert.h gone?

    - by Julian Kessel
    I want to get the hardware address of my mac's ethernet card. In all samples I saw in include on . Which seems not to exist on my system. GCC throws an error saying he doesn't know the type IOEthernetAddress. Is assert.h necessary for my task? It would be great if someone coud give me a working sample.

    Read the article

  • Should I be using assert in my PHP code?

    - by Darryl Hein
    A co-worker has added the assert command a few times within our libraries in places where I would have used an if statement and thrown an exception. (I had never even heard of assert before this.) Here is an example of how he used it: assert('isset($this->records); /* Records must be set before this is called. */'); I would have done: if ( ! isset($this->records) { throw new Exception('Records must be set before this is called'); } From reading the PHP docs on assert, it looks like it's recommended that make sure assert is active and add a handler before using assert. I can't find a place where he's done this. So, my question is, is using assert a good idea given the above and should I be using it more often instead of if's and exceptions?

    Read the article

  • Proper way to assert type of variable in Python

    - by Morlock
    In using a function, I wish to ensure that the type of the variables are as expected. How to do it right? Here is an example fake function trying to do just this before going on with its role: def my_print(text, begin, end): """Print text in UPPER between 'begin' and 'end' in lower """ for i in (text, begin, end): assert type(i) == type("") out = begin.lower() + text.upper() + end.lower() print out Is this approach valid? Should I use something else than type(i) == type("") ? Should I use try/except instead? Thanks pythoneers

    Read the article

  • Referring to this pointer in a static assert?

    - by Tyson Jacobs
    Is it possible to write a static assert referring to the 'this' pointer? I do not have c++11 available, and BOOST_STATIC_ASSERT doesn't work. struct blah { void func() {BOOST_STATIC_ASSERT(sizeof(*this));} }; Produces: error C2355: 'this' : can only be referenced inside non-static member functions error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE' In MSVC 2008. Motivation: #define CLASS_USES_SMALL_POOL() \ void __small_pool_check() {BOOST_STATIC_ASSERT(sizeof(*this) < SMALL_MALLOC_SIZE;} \ void* operator new(size_t) {return SmallMalloc();} \ void operator delete(void* p) {SmallFree(p);}

    Read the article

  • How to assert/unit-test servers JSON response?

    - by shazax
    My current project uses JSON as data interchange format. Both Front-end and Back-end team agree upon a JSON structure before start integrating a service. At times due to un-notified changes in JSON structure by back-end team; it breaks the front-end code. Is there any external library that we could use to compare a mock JSON (fixture) with servers JSON response. Basically it should assert the whole JSON object and should throw an error if there is any violation in servers JSON format. Additional info: App is built on JQuery consuming REST JSON services.

    Read the article

  • Debugging MinGW program with gdb on Windows, not terminating at assert failure

    - by devil
    How do I set up gdb on window so that it does not allow a program with assertion failure to terminate? I intend to check the stack trace and variables in the program. For example, running this test.cpp program compiled with MinGW 'g++ -g test.cpp -o test' in gdb: #include <cassert> int main(int argc, char ** argv) { assert(1==2); return 0; } Gives: $ gdb test.exe GNU gdb 6.8 Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-pc-mingw32"... (gdb) r Starting program: f:\code/test.exe [New thread 4616.0x1200] Error: dll starting at 0x77030000 not found. Error: dll starting at 0x75f80000 not found. Error: dll starting at 0x77030000 not found. Error: dll starting at 0x76f30000 not found. Assertion failed: 1==2, file test.cpp, line 2 This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Program exited with code 03. (gdb) I would like to be able to stop the program from terminating immediately, like how Visual Studio's debugger and gdb on Linux does it. I have done a search and found some stuff on trapping signals but I can't seem to find a good post on how to set up gdb to do this.

    Read the article

  • C++: static assert for const variables?

    - by shoosh
    Static asserts are very convenient for checking things in compile time. A simple static assert idiom looks like this: template<bool> struct StaticAssert; template<> struct StaticAssert<true> {}; #define STATIC_ASSERT(condition) do { StaticAssert<condition>(); } while(0) This is good for stuff like STATIC_ASSERT(sizeof(float) == 4) and: #define THIS_LIMIT (1000) ... STATIC_ASSERT(THIS_LIMIT > OTHER_LIMIT); But using #define is not the "C++" way of defining constants. C++ would have you use an anonymous namespace: namespace { const int THIS_LIMIT = 1000; } or even: static const int THIS_LIMIT = 1000; The trouble with this is that with a const int you can't use STATIC_ASSERT() and you must resort to a run-time check which is silly. Is there a way to properly solve this in current C++? I think I've read C++0x has some facility to do this...

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >