Search Results

Search found 49435 results on 1978 pages for 'query string'.

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

  • SQL SERVER – Quiz and Video – Introduction to Basics of a Query Hint

    - by pinaldave
    This blog post is inspired from SQL Architecture Basics Joes 2 Pros: Core Architecture concepts – SQL Exam Prep Series 70-433 – Volume 3. [Amazon] | [Flipkart] | [Kindle] | [IndiaPlaza] This is follow up blog post of my earlier blog post on the same subject - SQL SERVER – Introduction to Basics of a Query Hint – A Primer. In the article we discussed various basics terminology of the query hints. The article further covers following important concepts of query hints. Expecting Seek and getting a Scan Creating an index for improved optimization Implementing the query hint Above three are the most important concepts related to query hint and SQL Server.  There are many more things one has to learn but without beginners fundamentals one can’t learn the advanced  concepts. Let us have small quiz and check how many of you get the fundamentals right. Quiz 1) You have the following query: DECLARE @UlaChoice TinyInt SET @Type = 1 SELECT * FROM LegalActivity WHERE UlaChoice = @UlaChoice You have a nonclustered index named IX_Legal_Ula on the UlaChoice field. The Primary key is on the ID field and called PK_Legal_ID 99% of the time the value of the @UlaChoice is set to ‘YP101′. What query will achieve the best optimization for this query? SELECT * FROM LegalActivity WHERE UlaChoice = @UlaChoice WITH(INDEX(X_Legal_Ula)) SELECT * FROM LegalActivity WHERE UlaChoice = @UlaChoice WITH(INDEX(PK_Legal_ID)) SELECT * FROM LegalActivity WHERE UlaChoice = @UlaChoice OPTION (Optimize FOR(@UlaChoice = ‘YP101′)) 2) You have the following query: SELECT * FROM CurrentProducts WHERE ShortName = ‘Yoga Trip’ You have a nonclustered index on the ShortName field and the query runs an efficient index seek. You change your query to use a variable for ShortName and now you are using a slow index scan. What query hint can you use to get the same execution time as before? WITH LOCK FAST OPTIMIZE FOR MAXDOP READONLY Now make sure that you write down all the answers on the piece of paper. Watch following video and read earlier article over here. If you want to change the answer you still have chance. Solution 1) 3 2) 4 Now compare let us check the answers and compare your answers to following answers. I am very confident you will get them correct. Available at USA: Amazon India: Flipkart | IndiaPlaza Volume: 1, 2, 3, 4, 5 Please leave your feedback in the comment area for the quiz and video. Did you know all the answers of the quiz? Reference: Pinal Dave (http://blog.sqlauthority.com) Filed under: Joes 2 Pros, PostADay, SQL, SQL Authority, SQL Query, SQL Server, SQL Tips and Tricks, T SQL, Technology

    Read the article

  • SQL SERVER – Discard Results After Query Execution – SSMS

    - by pinaldave
    The first thing I do any day is to turn on the computer. Today I woke up and as soon as I turned on the computer I saw a chat message from a friend. He was a bit confused and wanted me to help him. Just as usual I am keeping the relevant conversation in focus and documenting our conversation as chat. Let us call him Ajit. Ajit: Pinal, every time I run a query there is no result displayed in the SSMS but when I run the query in my application it works and returns an appropriate result. Pinal:  Have you tried with different parameters? Ajit: Same thing. However, it works from another computer when I connect to the same server with the same query parameters? Pinal: What? That is new and I believe it is something to do with SSMS and not with the server. Send me screenshot please. Ajit: I believe so, let me send you a screenshot, Pinal: (looking at the screenshot) Oh man, there is no result-tab at all. Ajit: That is what the problem is. It does not have the tab which displays the result. This works just fine from another computer. Pinal: Have you referred Nakul’s blog post – SSMS – Query result options – Discard result after query executes, that talks about setting which can discard the query results after execution. (After a while) Ajit: I think it seems like on the computer where I am running the query my SSMS seems to have the option enabled related to discarding results. I fixed it by following Nakul’s blog post. Pinal: Great! Quite often I get the question what is the importance of the feature. Let us first see how to turn on or turn off this feature in SQL Server Management Studio 2012. In SSMS 2012 go to Tools >> Options >> Query Results > SQL Server >> Results to Grid >> Discard Results After Query Execution. When enabled this option will discard results after the execution. The advantage of disabling the option is that it will improve the performance by using less memory. However the real question is why would someone enable or disable the option. What are the cases when someone wants to run the query but do not care about the result? Matter of the fact, it does not make sense at all to run query and not care about the result. The matter of the fact, I can see quite a few reasons for using this option. I often enable this option when I am doing performance tuning exercise. During performance tuning exercise when I am working with execution plans and do not need results to verify every time or when I am tuning Indexes and its effect on execution plan I do not need the results. In this kind of situations I do keep this option on and discard the results. It always helps me big time as in most of the performance tuning exercise I am dealing with huge amount of the data and dealing with this data can be expensive. Nakul’s has done the experiment here already but I am going to repeat the same again using AdventureWorks Database. Run following T-SQL Script with and without enabling the option to discard the results. USE AdventureWorks2012 GO SELECT * FROM Sales.SalesOrderDetail GO 10 After enabling Discard Results After Query Execution After disabling Discard Results After Query Execution Well, this is indeed a good option when someone is debugging the execution plan or does not want the result to be displayed. Please note that this option does not reduce IO or CPU usage for SQL Server. It just discards the results after execution and a good help for debugging on the development server. Reference: Pinal Dave (http://blog.sqlauthority.com) Filed under: PostADay, SQL, SQL Authority, SQL Query, SQL Server, SQL Server Management Studio, SQL Tips and Tricks, T SQL, Technology

    Read the article

  • SQL server recursive query error.The maximum recursion 100 has been exhausted before statement completion

    - by ienax_ridens
    I have a recursive query that returns an error when I run it; in other databases (with more data) I have not the problem. In my case this query returns 2 colums (ID_PARENT and ID_CHILD) doing a recursion because my tree can have more than one level, bit I wanna have only "direct" parent. NOTE: I tried to put OPTION (MAXRECURSION 0) at the end of the query, but with no luck. The following query is only a part of the entire query, I tried to put OPTION only at the end of the "big query" having a continous running query, but no errors displayed. Error have in SQL Server: "The statement terminated.The maximum recursion 100 has been exhausted before statement completion" The query is the following: WITH q AS (SELECT ID_ITEM, ID_ITEM AS ID_ITEM_ANCESTOR FROM ITEMS_TABLE i JOIN ITEMS_TYPES_TABLE itt ON itt.ID_ITEM_TYPE = i.ID_ITEM_TYPE UNION ALL SELECT i.ID_ITEM, q.ID_ITEM_ANCESTOR FROM q JOIN ITEMS_TABLE i ON i.ID_ITEM_PADRE = q.ID_ITEM JOIN ITEMS_TYPES_TABLE itt ON itt.ID_ITEM_TYPE = i.ID_ITEM_TYPE) SELECT ID_ITEM AS ID_CHILD, ID_ITEM_ANCESTOR AS ID_PARENT FROM q I need a suggestion to re-write this query to avoid the error of recursion and see the data, that are few.

    Read the article

  • Complex string split in Java

    - by c0mrade
    Consider the following String : 5|12345|value1|value2|value3|value4+5|777|value1|value2|value3|value4?5|777|value1|value2|value3|value4+ Here is how I want to split string, split it with + so I get this result : myArray[0] = "5|12345|value1|value2|value3|value4"; myArray[1] = "5|777|value1|value2|value3|value4?5|777|value1|value2|value3|value4"; if string has doesn't contain char "?" split it with "|" and continue to part II, if string does contain "?" split it and for each part split it with "|" and continue to part II. Here is part II : myObject.setAttribute1(newString[0]); ... myObject.setAttribute4(newString[3]); Here what I've got so far : private static String input = "5|12345|value1|value2|value3|value4+5|777|value1|value2|value3|value4?5|777|value1|value2|value3|value4+"; public void mapObject(String input){ String[] myArray = null; if (input.contains("+")) { myArray = input.split("+"); } else { myArray = new String[1]; myArray[0] = input; } for (int i = 0; i < myArray.length; i++) { String[] secondaryArray = null; String[] myObjectAttribute = null; if (myArray[i].contains("?")) { secondaryArray = temporaryString.myArray[i].split("?"); for (String string : secondaryArray) { myObjectAttribute = string.split("\\|"); } } else { myObjectAttribute = myArray[i].toString().split("\\|"); } myObject.setAttribute1(myObjectAttribute[0]); ... myObject.setAttribute4(myObjectAttribute[3]); System.out.println(myObject.toString()); } Problem : When I split myArray, going trough for with myArray[0], everything set up nice as it should. Then comes the myArray[1], its split into two parts then the second part overrides the value of the first(how do I know that?). I've overridden toString() method of myObject, when I finish I print the set values so I know that it overrides it, does anybody know how can I fix this?

    Read the article

  • Random String Generator creates same string on multiple calls

    - by rockinthesixstring
    Hi there. I've build a random string generator but I'm having a problem whereby if I call the function multiple times say in a Page_Load method, the function returns the same string twice. here's the code ''' <summary>' ''' Generates a Random String' ''' </summary>' ''' <param name="n">number of characters the method should generate</param>' ''' <param name="UseSpecial">should the method include special characters? IE: # ,$, !, etc.</param>' ''' <param name="SpecialOnly">should the method include only the special characters and excludes alpha numeric</param>' ''' <returns>a random string n characters long</returns>' Public Function GenerateRandom(ByVal n As Integer, Optional ByVal UseSpecial As Boolean = True, Optional ByVal SpecialOnly As Boolean = False) As String Dim chars As String() ' a character array to use when generating a random string' Dim ichars As Integer = 74 'number of characters to use out of the chars string' Dim schars As Integer = 0 ' number of characters to skip out of the characters string' chars = { _ "A", "B", "C", "D", "E", "F", _ "G", "H", "I", "J", "K", "L", _ "M", "N", "O", "P", "Q", "R", _ "S", "T", "U", "V", "W", "X", _ "Y", "Z", "0", "1", "2", "3", _ "4", "5", "6", "7", "8", "9", _ "a", "b", "c", "d", "e", "f", _ "g", "h", "i", "j", "k", "l", _ "m", "n", "o", "p", "q", "r", _ "s", "t", "u", "v", "w", "x", _ "y", "z", "!", "@", "#", "$", _ "%", "^", "&", "*", "(", ")", _ "-", "+"} If Not UseSpecial Then ichars = 62 ' only use the alpha numeric characters out of "char"' If SpecialOnly Then schars = 62 : ichars = 74 ' skip the alpha numeric characters out of "char"' Dim rnd As New Random() Dim random As String = String.Empty Dim i As Integer = 0 While i < n random += chars(rnd.[Next](schars, ichars)) System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) End While rnd = Nothing Return random End Function but if I call something like this Dim str1 As String = GenerateRandom(5) Dim str2 As String = GenerateRandom(5) the response will be something like this g*3Jq g*3Jq and the second time I call it, it will be 3QM0$ 3QM0$ What am I missing? I'd like every random string to be generated as unique.

    Read the article

  • Replace apostrophe in json string with empty string

    - by user572844
    Hi, I have problem with deserialization of json string, because string is bad format. For example json object consist string property statusMessage with value "Hello "dog" ". The correct format should be "Hello \" dog \" " . I would like remove apostrophes from this property. Something Like this. "Hello "dog" ". - "Hello dog ". Here is it original json string which I work. "{\"jancl\":{\"idUser\":18438201,\"nick\":\"JANCl\",\"photo\":\"1\",\"sex\":1,\"photoAlbums\":1,\"videoAlbums\":0,\"sefNick\":\"jancl\",\"profilPercent\":75,\"emphasis\":false,\"age\":\"-\",\"isBlocked\":false,\"PHOTO\":{\"normal\":\"http://u.aimg.sk/fotky/1843/82/n_18438201.jpg?v=1\",\"medium\":\"http://u.aimg.sk/fotky/1843/82/m_18438201.jpg?v=1\",\"24x24\":\"http://u.aimg.sk/fotky/1843/82/s_18438201.jpg?v=1\"},\"PLUS\":{\"active\":false,\"activeTo\":\"0000-00-00\"},\"LOCATION\":{\"idRegion\":\"6\",\"regionName\":\"Trenciansky kraj\",\"idCity\":\"138\",\"cityName\":\"Trencianske Teplice\"},\"STATUS\":{\"isLoged\":true,\"isChating\":false,\"idChat\":0,\"roomName\":\"\",\"lastLogin\":1294925369},\"PROJECT_STATUS\":{\"photoAlbums\":1,\"photoAlbumsFavs\":0,\"videoAlbums\":0,\"videoAlbumsFavs\":0,\"videoAlbumsExts\":0,\"blogPosts\":0,\"emailNew\":0,\"postaNew\":0,\"clubInvitations\":0,\"dashboardItems\":1},\"STATUS_MESSAGE\":{\"statusMessage\":\"\"Status\"\",\"addTime\":\"1294872330\"},\"isFriend\":false,\"isIamFriend\":false}}" Problem is here, json string consist this object: "STATUS_MESSAGE": {"statusMessage":" "some "bad" value" ", "addTime" :"1294872330"} Condition of string which I want modified: string start with "statusMessage":" string can has any *lenght from 0 -N * string end with ", "addTime So I try write pattern for string which start with "statusMessage":", has any lenght and is ended with ", "addTime. Here is it: const string pattern = " \" statusMessage \" : \" .*? \",\"addTime\" "; var regex = new Regex(pattern, RegexOptions.IgnoreCase); //here i would replace " with empty string string result = regex.Replace(jsonString, match => ???); But I think pattern is wrong, also I don’t know how replace apostrophe with empty string (remove apostrophne). My goal is : "statusMessage":" "some "bad" value" to "statusMessage":" "some bad value" Thank for advice

    Read the article

  • Set fields with instrospection - Problem with String.valueOf(String)

    - by fabb
    Hey there! I'm setting public fields of the Object 'this' via reflection. Both the field name and the value are given as String. I use several various field types: Boolean, Integer, Float, Double, an own enum, and a String. It works with all of them except with a String. The exception that gets thrown is that no method with the Signature String.valueOf(String) exists... Now I use a dirty instanceof workaround to detect if each field is a String and in that case just copy the value to the field. private void setField(String field, String value) throws Exception { Field wField = this.getClass().getField(field); if(wField.get(this) instanceof String){ //TODO dirrrrty hack //stupid workaround as java.lang.String.valueOf(java.lang.String) fails... wField.set(this, value); }else{ Method parseMethod = wField.getType().getMethod("valueOf", new Class[]{String.class}); wField.set(this, parseMethod.invoke(wField, value)); } } Any ideas how to avoid that workaround? Do you think java.lang.String should support the method valueOf(String)? thanks, fabb

    Read the article

  • SQL SERVER – How to Ignore Columnstore Index Usage in Query

    - by pinaldave
    Earlier I wrote about SQL SERVER – Fundamentals of Columnstore Index and very first question I received in email was as following. “We are using SQL Server 2012 CTP3 and so far so good. In our data warehouse solution we have created 1 non-clustered columnstore index on our large fact table. We have very unique situation but your article did not cover it. We are running few queries on our fact table which is working very efficiently but there is one query which earlier was running very fine but after creating this non-clustered columnstore index this query is running very slow. We dropped the columnstore index and suddenly this one query is running fast but other queries which were benefited by this columnstore index it is running slow. Any workaround in this situation?” In summary the question in simple words “How can we ignore using columnstore index in selective queries?” Very interesting question – you can use I can understand there may be the cases when columnstore index is not ideal and needs to be ignored the same. You can use the query hint IGNORE_NONCLUSTERED_COLUMNSTORE_INDEX to ignore the columnstore index. SQL Server Engine will use any other index which is best after ignoring the columnstore index. Here is the quick script to prove the same. We will first create sample database and then create columnstore index on the same. Once columnstore index is created we will write simple query. This query will use columnstore index. We will then show the usage of the query hint. USE AdventureWorks GO -- Create New Table CREATE TABLE [dbo].[MySalesOrderDetail]( [SalesOrderID] [int] NOT NULL, [SalesOrderDetailID] [int] NOT NULL, [CarrierTrackingNumber] [nvarchar](25) NULL, [OrderQty] [smallint] NOT NULL, [ProductID] [int] NOT NULL, [SpecialOfferID] [int] NOT NULL, [UnitPrice] [money] NOT NULL, [UnitPriceDiscount] [money] NOT NULL, [LineTotal] [numeric](38, 6) NOT NULL, [rowguid] [uniqueidentifier] NOT NULL, [ModifiedDate] [datetime] NOT NULL ) ON [PRIMARY] GO -- Create clustered index CREATE CLUSTERED INDEX [CL_MySalesOrderDetail] ON [dbo].[MySalesOrderDetail] ( [SalesOrderDetailID]) GO -- Create Sample Data Table -- WARNING: This Query may run upto 2-10 minutes based on your systems resources INSERT INTO [dbo].[MySalesOrderDetail] SELECT S1.* FROM Sales.SalesOrderDetail S1 GO 100 -- Create ColumnStore Index CREATE NONCLUSTERED COLUMNSTORE INDEX [IX_MySalesOrderDetail_ColumnStore] ON [MySalesOrderDetail] (UnitPrice, OrderQty, ProductID) GO Now we have created columnstore index so if we run following query it will use for sure the same index. -- Select Table with regular Index SELECT ProductID, SUM(UnitPrice) SumUnitPrice, AVG(UnitPrice) AvgUnitPrice, SUM(OrderQty) SumOrderQty, AVG(OrderQty) AvgOrderQty FROM [dbo].[MySalesOrderDetail] GROUP BY ProductID ORDER BY ProductID GO We can specify Query Hint IGNORE_NONCLUSTERED_COLUMNSTORE_INDEX as described in following query and it will not use columnstore index. -- Select Table with regular Index SELECT ProductID, SUM(UnitPrice) SumUnitPrice, AVG(UnitPrice) AvgUnitPrice, SUM(OrderQty) SumOrderQty, AVG(OrderQty) AvgOrderQty FROM [dbo].[MySalesOrderDetail] GROUP BY ProductID ORDER BY ProductID OPTION (IGNORE_NONCLUSTERED_COLUMNSTORE_INDEX) GO Let us clean up the database. -- Cleanup DROP INDEX [IX_MySalesOrderDetail_ColumnStore] ON [dbo].[MySalesOrderDetail] GO TRUNCATE TABLE dbo.MySalesOrderDetail GO DROP TABLE dbo.MySalesOrderDetail GO Again, make sure that you use hint sparingly and understanding the proper implication of the same. Make sure that you test it with and without hint and select the best option after review of your administrator. Here is the question for you – have you started to use SQL Server 2012 for your validation and development (not on production)? It will be interesting to know the answer. Reference: Pinal Dave (http://blog.SQLAuthority.com) Filed under: PostADay, SQL, SQL Authority, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, T SQL, Technology

    Read the article

  • Suggestion to reverse string in c#

    - by HasanGursoy
    Is this the right method to reverse a string? I'm planning to use it to reverse a string like: Products » X1 » X3 to X3 « X1 « Products I want it to be a global function which can be used elsewhere. public static string ReverseString(string input, string separator, string outSeparator) { string result = String.Empty; string[] temp = Regex.Split(input, separator, RegexOptions.IgnoreCase); Array.Reverse(temp); for (int i = 0; i < temp.Length; i++) { result += temp[i] + " " + outSeparator + " "; } return result; }

    Read the article

  • Best practice for string substition with gettext using Python

    - by Malcolm
    Looking for best practice advice on what string substitution technique to use when using gettext(). Or do all techniques apply equally? I can think of at least 3 string techniques: Classic "%" based formatting: "My name is %(name)s" % locals() .format() based formatting: "My name is {name}".format( locals() ) string.Template.safe_substitute() import string template = string.Template( "My name is ${name}" ) template.safe_substitute( locals() ) The advantage of the string.Template technique is that a translated string with with an incorrectly spelled variable reference can still yield a usable string value while the other techniques unconditionally raise an exception. The downside of the string.Template technique appears to be the inability for one to customize how a variable is formatted (padding, justification, width, etc).

    Read the article

  • Translating C++'s sprintf format string to C#'s string.Format

    - by thebackup
    I found the following C++ code (comments added myself): // frame_name is a char array // prefix is std::string // k is a for loop counter // frames is a std::vector string sprintf(frameName, "%s_%0*s.bmp", prefix.c_str(), k, frames[k].c_str()); I then try to translate it to C# // prefix is string // k is a for loop counter // frames is List<string> string frameName = string.Format("{0}_(what goes in here?).bmp", prefix, k, frames[k]); Basically, what would be the C# equivalent of the C++ format string "%s_%0*s.bmp"?

    Read the article

  • SQL – Quick Start with Explorer Sections of NuoDB – Query NuoDB Database

    - by Pinal Dave
    This is the third post in the series of the blog posts I am writing about NuoDB. NuoDB is very innovative and easy-to-use product. I can clearly see how one can scale-out NuoDB with so much ease and confidence. In my very first blog post we discussed how we can install NuoDB (link), and in my second post I discussed how we can manage the NuoDB database transaction engines and storage managers with a few clicks (link). Note: You can Download NuoDB from here. In this post, we will learn how we can use the Explorer feature of NuoDB to do various SQL operations. NuoDB has a browser-based Explorer, which is very powerful and has many of the features any IDE would normally have. Let us see how it works in the following step-by-step tutorial. Let us go to the NuoDBNuoDB Console by typing the following URL in your browser: http://localhost:8080/ It will bring you to the QuickStart screen. Make sure that you have created the sample database. If you have not created sample database, click on Create Database and create it successfully. Now go to the NuoDB Explorer by clicking on the main tab, and it will ask you for your domain username and password. Enter the username as a domain and password as a bird. Alternatively you can also enter username as a quickstart and password as a quickstart. Once you enter the password you will be able to see the databases. In our example we have installed the Sample Database hence you will see the Test database in our Database Hierarchy screen. When you click on database it will ask for the database login. Note that Database Login is different from Domain login and you will have to enter your database login over here. In our case the database username is dba and password is goalie. Once you enter a valid username and password it will display your database. Further expand your database and you will notice various objects in your database. Once you explore various objects, select any database and click on Open. When you click on execute, it will display the SQL script to select the data from the table. The autogenerated script displays entire result set from the database. The NuoDB Explorer is very powerful and makes the life of developers very easy. If you click on List SQL Statements it will list all the available SQL statements right away in Query Editor. You can see the popup window in following image. Here is the cool thing for geeks. You can even click on Query Plan and it will display the text based query plan as well. In case of a SELECT, the query plan will be much simpler, however, when we write complex queries it will be very interesting. We can use the query plan tab for performance tuning of the database. Here is another feature, when we click on List Tables in NuoDB Explorer.  It lists all the available tables in the query editor. This is very helpful when we are writing a long complex query. Here is a relatively complex example I have built using Inner Join syntax. Right below I have displayed the Query Plan. The query plan displays all the little details related to the query. Well, we just wrote multi-table query and executed it against the NuoDB database. You can use the NuoDB Admin section and do various analyses of the query and its performance. NuoDB is a distributed database built on a patented emergent architecture with full support for SQL and ACID guarantees.  It allows you to add Transaction Engine processes to a running system to improve the performance of your system.  You can also add a second Storage Engine to your running system for redundancy purposes.  Conversely, you can shut down processes when you don’t need the extra database resources. NuoDB also provides developers and administrators with a single intuitive interface for centrally monitoring deployments. If you have read my blog posts and have not tried out NuoDB, I strongly suggest that you download it today and catch up with the learnings with me. Trust me though the product is very powerful, it is extremely easy to learn and use. Reference: Pinal Dave (http://blog.sqlauthority.com)   Filed under: Big Data, PostADay, SQL, SQL Authority, SQL Query, SQL Server, SQL Tips and Tricks, T SQL, Technology Tagged: NuoDB

    Read the article

  • Trying to convert simple midlet application to Android application but running into problems.

    - by chobo2
    Hi I am trying to do some threading in Android so I took an old threading assignment I had done fora midlet and took out the midlet code and replaced it with android code(such as textview). package com.assignment1; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class Threading extends Activity { private TextView tortose; private TextView hare; private Thread hareThread; private Thread torotoseThread; private int num = 0; private int num2 = 0; public Threading() { } /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tortose = (TextView) findViewById(R.id.TextView01); hare = (TextView) findViewById(R.id.TextView02); Hare newHare = new Hare(); hareThread = new Thread(newHare); hareThread.start(); Torotose newTortose = new Torotose(); torotoseThread = new Thread(newTortose); torotoseThread.start(); //updateDisplay(); } private synchronized void check(int value1, int value2) { if((value1-value2) >= 10) { try { wait(); } catch(Exception ex) { System.out.println(ex); } } } private synchronized void getGoing(int value1, int value2) { if((value1-value2) == 0) { try { notify(); } catch(Exception ex) { System.out.println(ex); } } } private class Hare extends Thread { public void run() { while(true) { num++; hare.setText(Integer.toString(num)); check(num, num2); try { // are threads different in andriod apps? Thread.sleep(100); // hareThread.sleep(100); } catch(Exception ex) { System.out.println(ex); } } } } private class Torotose extends Thread { public void run() { while(true) { num2++; tortose.setText(Integer.toString(num2)); getGoing(num,num2); try { Thread.sleep(200); //torotoseThread.sleep(200); } catch(Exception ex) { System.out.println(ex); } } } } } First it wanted me to change my threads to like static threads.So is this just how Android does it? Next when I run this code it just crashes with some unexpected error. I am not sure what the error is but when I try to debug it and goes to like to create a new "hare" object it shows me this. // Compiled from ClassLoader.java (version 1.5 : 49.0, super bit) public abstract class java.lang.ClassLoader { // Method descriptor #8 ()V // Stack: 3, Locals: 1 protected ClassLoader(); 0 aload_0 [this] 1 invokespecial java.lang.Object() [1] 4 new java.lang.RuntimeException [2] 7 dup 8 ldc <String "Stub!"> [3] 10 invokespecial java.lang.RuntimeException(java.lang.String) [4] 13 athrow Line numbers: [pc: 0, line: 4] Local variable table: [pc: 0, pc: 14] local: this index: 0 type: java.lang.ClassLoader // Method descriptor #14 (Ljava/lang/ClassLoader;)V // Stack: 3, Locals: 2 protected ClassLoader(java.lang.ClassLoader parentLoader); 0 aload_0 [this] 1 invokespecial java.lang.Object() [1] 4 new java.lang.RuntimeException [2] 7 dup 8 ldc <String "Stub!"> [3] 10 invokespecial java.lang.RuntimeException(java.lang.String) [4] 13 athrow Line numbers: [pc: 0, line: 5] Local variable table: [pc: 0, pc: 14] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 14] local: parentLoader index: 1 type: java.lang.ClassLoader // Method descriptor #17 ()Ljava/lang/ClassLoader; // Stack: 3, Locals: 0 public static java.lang.ClassLoader getSystemClassLoader(); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 6] // Method descriptor #19 (Ljava/lang/String;)Ljava/net/URL; // Stack: 3, Locals: 1 public static java.net.URL getSystemResource(java.lang.String resName); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 7] Local variable table: [pc: 0, pc: 10] local: resName index: 0 type: java.lang.String // Method descriptor #23 (Ljava/lang/String;)Ljava/util/Enumeration; // Signature: (Ljava/lang/String;)Ljava/util/Enumeration<Ljava/net/URL;>; // Stack: 3, Locals: 1 public static java.util.Enumeration getSystemResources(java.lang.String resName) throws java.io.IOException; 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 8] Local variable table: [pc: 0, pc: 10] local: resName index: 0 type: java.lang.String // Method descriptor #29 (Ljava/lang/String;)Ljava/io/InputStream; // Stack: 3, Locals: 1 public static java.io.InputStream getSystemResourceAsStream(java.lang.String resName); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 9] Local variable table: [pc: 0, pc: 10] local: resName index: 0 type: java.lang.String // Method descriptor #31 ([BII)Ljava/lang/Class; // Signature: ([BII)Ljava/lang/Class<*>; // Stack: 3, Locals: 4 protected final java.lang.Class defineClass(byte[] classRep, int offset, int length) throws java.lang.ClassFormatError; 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 10] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: classRep index: 1 type: byte[] [pc: 0, pc: 10] local: offset index: 2 type: int [pc: 0, pc: 10] local: length index: 3 type: int // Method descriptor #39 (Ljava/lang/String;[BII)Ljava/lang/Class; // Signature: (Ljava/lang/String;[BII)Ljava/lang/Class<*>; // Stack: 3, Locals: 5 protected final java.lang.Class defineClass(java.lang.String className, byte[] classRep, int offset, int length) throws java.lang.ClassFormatError; 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 11] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: className index: 1 type: java.lang.String [pc: 0, pc: 10] local: classRep index: 2 type: byte[] [pc: 0, pc: 10] local: offset index: 3 type: int [pc: 0, pc: 10] local: length index: 4 type: int // Method descriptor #42 (Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class; // Signature: (Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class<*>; // Stack: 3, Locals: 6 protected final java.lang.Class defineClass(java.lang.String className, byte[] classRep, int offset, int length, java.security.ProtectionDomain protectionDomain) throws java.lang.ClassFormatError; 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 12] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: className index: 1 type: java.lang.String [pc: 0, pc: 10] local: classRep index: 2 type: byte[] [pc: 0, pc: 10] local: offset index: 3 type: int [pc: 0, pc: 10] local: length index: 4 type: int [pc: 0, pc: 10] local: protectionDomain index: 5 type: java.security.ProtectionDomain // Method descriptor #46 (Ljava/lang/String;Ljava/nio/ByteBuffer;Ljava/security/ProtectionDomain;)Ljava/lang/Class; // Signature: (Ljava/lang/String;Ljava/nio/ByteBuffer;Ljava/security/ProtectionDomain;)Ljava/lang/Class<*>; // Stack: 3, Locals: 4 protected final java.lang.Class defineClass(java.lang.String name, java.nio.ByteBuffer b, java.security.ProtectionDomain protectionDomain) throws java.lang.ClassFormatError; 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 13] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: name index: 1 type: java.lang.String [pc: 0, pc: 10] local: b index: 2 type: java.nio.ByteBuffer [pc: 0, pc: 10] local: protectionDomain index: 3 type: java.security.ProtectionDomain // Method descriptor #52 (Ljava/lang/String;)Ljava/lang/Class; // Signature: (Ljava/lang/String;)Ljava/lang/Class<*>; // Stack: 3, Locals: 2 protected java.lang.Class findClass(java.lang.String className) throws java.lang.ClassNotFoundException; 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 14] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: className index: 1 type: java.lang.String // Method descriptor #52 (Ljava/lang/String;)Ljava/lang/Class; // Signature: (Ljava/lang/String;)Ljava/lang/Class<*>; // Stack: 3, Locals: 2 protected final java.lang.Class findLoadedClass(java.lang.String className); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 15] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: className index: 1 type: java.lang.String // Method descriptor #52 (Ljava/lang/String;)Ljava/lang/Class; // Signature: (Ljava/lang/String;)Ljava/lang/Class<*>; // Stack: 3, Locals: 2 protected final java.lang.Class findSystemClass(java.lang.String className) throws java.lang.ClassNotFoundException; 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 16] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: className index: 1 type: java.lang.String // Method descriptor #17 ()Ljava/lang/ClassLoader; // Stack: 3, Locals: 1 public final java.lang.ClassLoader getParent(); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 17] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader // Method descriptor #19 (Ljava/lang/String;)Ljava/net/URL; // Stack: 3, Locals: 2 public java.net.URL getResource(java.lang.String resName); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 18] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: resName index: 1 type: java.lang.String // Method descriptor #23 (Ljava/lang/String;)Ljava/util/Enumeration; // Signature: (Ljava/lang/String;)Ljava/util/Enumeration<Ljava/net/URL;>; // Stack: 3, Locals: 2 public java.util.Enumeration getResources(java.lang.String resName) throws java.io.IOException; 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 19] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: resName index: 1 type: java.lang.String // Method descriptor #29 (Ljava/lang/String;)Ljava/io/InputStream; // Stack: 3, Locals: 2 public java.io.InputStream getResourceAsStream(java.lang.String resName); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 20] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: resName index: 1 type: java.lang.String // Method descriptor #52 (Ljava/lang/String;)Ljava/lang/Class; // Signature: (Ljava/lang/String;)Ljava/lang/Class<*>; // Stack: 3, Locals: 2 public java.lang.Class loadClass(java.lang.String className) throws java.lang.ClassNotFoundException; 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 21] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: className index: 1 type: java.lang.String // Method descriptor #62 (Ljava/lang/String;Z)Ljava/lang/Class; // Signature: (Ljava/lang/String;Z)Ljava/lang/Class<*>; // Stack: 3, Locals: 3 protected java.lang.Class loadClass(java.lang.String className, boolean resolve) throws java.lang.ClassNotFoundException; 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 22] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: className index: 1 type: java.lang.String [pc: 0, pc: 10] local: resolve index: 2 type: boolean // Method descriptor #67 (Ljava/lang/Class;)V // Signature: (Ljava/lang/Class<*>;)V // Stack: 3, Locals: 2 protected final void resolveClass(java.lang.Class clazz); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 23] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: clazz index: 1 type: java.lang.Class Local variable type table: [pc: 0, pc: 10] local: clazz index: 1 type: java.lang.Class<?> // Method descriptor #19 (Ljava/lang/String;)Ljava/net/URL; // Stack: 3, Locals: 2 protected java.net.URL findResource(java.lang.String resName); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 24] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: resName index: 1 type: java.lang.String // Method descriptor #23 (Ljava/lang/String;)Ljava/util/Enumeration; // Signature: (Ljava/lang/String;)Ljava/util/Enumeration<Ljava/net/URL;>; // Stack: 3, Locals: 2 protected java.util.Enumeration findResources(java.lang.String resName) throws java.io.IOException; 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 25] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: resName index: 1 type: java.lang.String // Method descriptor #76 (Ljava/lang/String;)Ljava/lang/String; // Stack: 3, Locals: 2 protected java.lang.String findLibrary(java.lang.String libName); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 26] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: libName index: 1 type: java.lang.String // Method descriptor #79 (Ljava/lang/String;)Ljava/lang/Package; // Stack: 3, Locals: 2 protected java.lang.Package getPackage(java.lang.String name); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 27] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: name index: 1 type: java.lang.String // Method descriptor #81 ()[Ljava/lang/Package; // Stack: 3, Locals: 1 protected java.lang.Package[] getPackages(); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 28] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader // Method descriptor #83 (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/net/URL;)Ljava/lang/Package; // Stack: 3, Locals: 9 protected java.lang.Package definePackage(java.lang.String name, java.lang.String specTitle, java.lang.String specVersion, java.lang.String specVendor, java.lang.String implTitle, java.lang.String implVersion, java.lang.String implVendor, java.net.URL sealBase) throws java.lang.IllegalArgumentException; 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 29] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: name index: 1 type: java.lang.String [pc: 0, pc: 10] local: specTitle index: 2 type: java.lang.String [pc: 0, pc: 10] local: specVersion index: 3 type: java.lang.String [pc: 0, pc: 10] local: specVendor index: 4 type: java.lang.String [pc: 0, pc: 10] local: implTitle index: 5 type: java.lang.String [pc: 0, pc: 10] local: implVersion index: 6 type: java.lang.String [pc: 0, pc: 10] local: implVendor index: 7 type: java.lang.String [pc: 0, pc: 10] local: sealBase index: 8 type: java.net.URL // Method descriptor #94 (Ljava/lang/Class;[Ljava/lang/Object;)V // Signature: (Ljava/lang/Class<*>;[Ljava/lang/Object;)V // Stack: 3, Locals: 3 protected final void setSigners(java.lang.Class c, java.lang.Object[] signers); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 30] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: c index: 1 type: java.lang.Class [pc: 0, pc: 10] local: signers index: 2 type: java.lang.Object[] Local variable type table: [pc: 0, pc: 10] local: c index: 1 type: java.lang.Class<?> // Method descriptor #100 (Ljava/lang/String;Z)V // Stack: 3, Locals: 3 public void setClassAssertionStatus(java.lang.String cname, boolean enable); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 31] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: cname index: 1 type: java.lang.String [pc: 0, pc: 10] local: enable index: 2 type: boolean // Method descriptor #100 (Ljava/lang/String;Z)V // Stack: 3, Locals: 3 public void setPackageAssertionStatus(java.lang.String pname, boolean enable); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 32] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: pname index: 1 type: java.lang.String [pc: 0, pc: 10] local: enable index: 2 type: boolean // Method descriptor #106 (Z)V // Stack: 3, Locals: 2 public void setDefaultAssertionStatus(boolean enable); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 33] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader [pc: 0, pc: 10] local: enable index: 1 type: boolean // Method descriptor #8 ()V // Stack: 3, Locals: 1 public void clearAssertionStatus(); 0 new java.lang.RuntimeException [2] 3 dup 4 ldc <String "Stub!"> [3] 6 invokespecial java.lang.RuntimeException(java.lang.String) [4] 9 athrow Line numbers: [pc: 0, line: 34] Local variable table: [pc: 0, pc: 10] local: this index: 0 type: java.lang.ClassLoader } So I am not sure where I went wrong. Thanks

    Read the article

  • How can I make nested string splits?

    - by Statement
    I have what seemed at first to be a trivial problem but turned out to become something I can't figure out how to easily solve. I need to be able to store lists of items in a string. Then those items in turn can be a list, or some other value that may contain my separator character. I have two different methods that unpack the two different cases but I realized I need to encode the contained value from any separator characters used with string.Split. To illustrate the problem: string[] nested = { "mary;john;carl", "dog;cat;fish", "plainValue" } string list = string.Join(";", nested); string[] unnested = list.Split(';'); // EEK! returns 7 items, expected 3! This would produce a list "mary;john;carl;dog;cat;fish;plainValue", a value I can't split to get the three original nested strings from. Indeed, instead of the three original strings, I'd get 7 strings on split and this approach thus doesn't work at all. What I want is to allow the values in my string to be encoded so I can unpack/split the contents just the way before I packed/join them. I assume I might need to go away from string.Split and string.Join and that is perfectly fine. I might just have overlooked some useful class or method. How can I allow any string values to be packed / unpacked into lists? I prefer neat, simple solutions over bulky if possible. For the curious mind, I am making extensions for PlayerPrefs in Unity3D, and I can only work with ints, floats and strings. Thus I chose strings to be my data carrier. This is why I am making this nested list of strings.

    Read the article

  • How safe and reliable are C++ String Literals?

    - by DoctorT
    So, I'm wanting to get a better grasp on how string literals in C++ work. I'm mostly concerned with situations where you're assigning the address of a string literal to a pointer, and passing it around. For example: char* advice = "Don't stick your hands in the toaster."; Now lets say I just pass this string around by copying pointers for the duration of the program. Sure, it's probably not a good idea, but I'm curious what would actually be going on behind the scenes. For another example, let's say we make a function that returns a string literal: char* foo() { // function does does stuff return "Yikes!"; // somebody's feeble attempt at an error message } Now lets say this function is called very often, and the string literal is only used about half the time it's called: // situation #1: it's just randomly called without heed to the return value foo(); // situation #2: the returned string is kept and used for who knows how long char* retVal = foo(); In the first situation, what's actually happening? Is the string just created but not used, and never deallocated? In the second situation, is the string going to be maintained as long as the user finds need for it? What happens when it isn't needed anymore... will that memory be freed up then (assuming nothing points to that space anymore)? Don't get me wrong, I'm not planning on using string literals like this. I'm planning on using a container to keep my strings in check (probably std::string). I'm mostly just wanting to know if these situations could cause problems either for memory management or corrupted data.

    Read the article

  • Mysql 100% CPU + Slow query

    - by felipeclopes
    I'm using the RDS database from amazon with a some very big tables, and yesterday I started to face 100% CPU utilisation on the server and a bunch of slow query logs that were not happening before. I tried to check the queries that were running and faced this result from the explain command +----+-------------+-------------------------------+--------+----------------------------------------------------------------------------------------------+---------------------------------------+---------+-----------------------------------------------------------------+------+----------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------------------------------+--------+----------------------------------------------------------------------------------------------+---------------------------------------+---------+-----------------------------------------------------------------+------+----------------------------------------------+ | 1 | SIMPLE | businesses | const | PRIMARY | PRIMARY | 4 | const | 1 | Using index; Using temporary; Using filesort | | 1 | SIMPLE | activities_businesses | ref | PRIMARY,index_activities_users_on_business_id,index_tweets_users_on_tweet_id_and_business_id | index_activities_users_on_business_id | 9 | const | 2252 | Using index condition; Using where | | 1 | SIMPLE | activities_b_taggings_975e9c4 | ref | taggings_idx | taggings_idx | 782 | const,myapp_production.activities_businesses.id,const | 1 | Using index condition; Using where | | 1 | SIMPLE | activities | eq_ref | PRIMARY,index_activities_on_created_at | PRIMARY | 8 | myapp_production.activities_businesses.activity_id | 1 | Using where | +----+-------------+-------------------------------+--------+----------------------------------------------------------------------------------------------+---------------------------------------+---------+-----------------------------------------------------------------+------+----------------------------------------------+ Also checkin in the process list, I got something like this: +----+-----------------+-------------------------------------+----------------------------+---------+------+--------------+------------------------------------------------------------------------------------------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+-----------------+-------------------------------------+----------------------------+---------+------+--------------+------------------------------------------------------------------------------------------------------+ | 1 | my_app | my_ip:57152 | my_app_production | Sleep | 0 | | NULL | | 2 | my_app | my_ip:57153 | my_app_production | Sleep | 2 | | NULL | | 3 | rdsadmin | localhost:49441 | NULL | Sleep | 9 | | NULL | | 6 | my_app | my_other_ip:47802 | my_app_production | Sleep | 242 | | NULL | | 7 | my_app | my_other_ip:47807 | my_app_production | Query | 231 | Sending data | SELECT my_fields... | | 8 | my_app | my_other_ip:47809 | my_app_production | Query | 231 | Sending data | SELECT my_fields... | | 9 | my_app | my_other_ip:47810 | my_app_production | Query | 231 | Sending data | SELECT my_fields... | | 10 | my_app | my_other_ip:47811 | my_app_production | Query | 231 | Sending data | SELECT my_fields... | | 11 | my_app | my_other_ip:47813 | my_app_production | Query | 231 | Sending data | SELECT my_fields... | ... So based on the numbers, it looks like there is no reason to have a slow query, since the worst execution plan is the one that goes through 2k rows which is not much. Edit 1 Another information that might be useful is the slow query_log SET timestamp=1401457485; SELECT my_query... # User@Host: myapp[myapp] @ ip-10-195-55-233.ec2.internal [IP] Id: 435 # Query_time: 95.830497 Lock_time: 0.000178 Rows_sent: 0 Rows_examined: 1129387 Edit 2 After profiling, I got this result. The result have approximately 250 rows with two columns each. +----------------------+----------+ | state | duration | +----------------------+----------+ | Sending data | 272 | | removing tmp table | 0 | | optimizing | 0 | | Creating sort index | 0 | | init | 0 | | cleaning up | 0 | | executing | 0 | | checking permissions | 0 | | freeing items | 0 | | Creating tmp table | 0 | | query end | 0 | | statistics | 0 | | end | 0 | | System lock | 0 | | Opening tables | 0 | | logging slow query | 0 | | Sorting result | 0 | | starting | 0 | | closing tables | 0 | | preparing | 0 | +----------------------+----------+ Edit 3 Adding query as requested SELECT activities.share_count, activities.created_at FROM `activities_businesses` INNER JOIN `businesses` ON `businesses`.`id` = `activities_businesses`.`business_id` INNER JOIN `activities` ON `activities`.`id` = `activities_businesses`.`activity_id` JOIN taggings activities_b_taggings_975e9c4 ON activities_b_taggings_975e9c4.taggable_id = activities_businesses.id AND activities_b_taggings_975e9c4.taggable_type = 'ActivitiesBusiness' AND activities_b_taggings_975e9c4.tag_id = 104 AND activities_b_taggings_975e9c4.created_at >= '2014-04-30 13:36:44' WHERE ( businesses.id = 1 ) AND ( activities.created_at > '2014-04-30 13:36:44' ) AND ( activities.created_at < '2014-05-30 12:27:03' ) ORDER BY activities.created_at; Edit 4 There may be a chance that the indexes are not being applied due to difference in column type between the taggings and the activities_businesses, on the taggable_id column. mysql> SHOW COLUMNS FROM activities_businesses; +-------------+------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | activity_id | bigint(20) | YES | MUL | NULL | | | business_id | bigint(20) | YES | MUL | NULL | | +-------------+------------+------+-----+---------+----------------+ 3 rows in set (0.01 sec) mysql> SHOW COLUMNS FROM taggings; +---------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | tag_id | int(11) | YES | MUL | NULL | | | taggable_id | bigint(20) | YES | | NULL | | | taggable_type | varchar(255) | YES | | NULL | | | tagger_id | int(11) | YES | | NULL | | | tagger_type | varchar(255) | YES | | NULL | | | context | varchar(128) | YES | | NULL | | | created_at | datetime | YES | | NULL | | +---------------+--------------+------+-----+---------+----------------+ So it is examining way more rows than it shows in the explain query, probably because some indexes are not being applied. Do you guys can help m with that?

    Read the article

  • SQLAuthority News – Statistics Used by the Query Optimizer in Microsoft SQL Server 2008 – Microsoft Whitepaper

    - by pinaldave
    I recently presented session on Statistics and Best Practices in Virtual Tech Days on Nov 22, 2010. The sessions was very popular and I got many questions right after the sessions. The number question I had received was where everybody can get the further information. I am very much happy that my sessions created some curiosity for one of the most important feature of the SQL Server. Statistics are the heart of the SQL Server. Microsoft has published a white paper on the subject how statistics are useful to Query Optimizer. Here is the abstract of the same white paper from Microsoft. Statistics Used by the Query Optimizer in Microsoft SQL Server 2008 Writer: Eric N. Hanson and Yavor Angelov Microsoft SQL Server 2008 collects statistical information about indexes and column data stored in the database. These statistics are used by the SQL Server query optimizer to choose the most efficient plan for retrieving or updating data. This paper describes what data is collected, where it is stored, and which commands create, update, and delete statistics. By default, SQL Server 2008 also creates and updates statistics automatically, when such an operation is considered to be useful. This paper also outlines how these defaults can be changed on different levels (column, table, and database). In addition, it presents how certain query language features, such as Transact-SQL variables, interact with use of statistics by the optimizer, and it provides guidance for using these features when writing queries so you can obtain good query performance. Link to white paper Statistics Used by the Query Optimizer in Microsoft SQL Server 2008 ?Reference: Pinal Dave (http://blog.SQLAuthority.com)   Filed under: Pinal Dave, SQL, SQL Authority, SQL Documentation, SQL Download, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQL White Papers, SQLAuthority News, T SQL, Technology

    Read the article

  • Shortest Common Superstring: find shortest string that contains all given string fragments

    - by occulus
    Given some string fragments, I would like to find the shortest possible single string ("output string") that contains all the fragments. Fragments can overlap each other in the output string. Example: For the string fragments: BCDA AGF ABC The following output string contains all fragments, and was made by naive appending: BCDAAGFABC However this output string is better (shorter), as it employs overlaps: ABCDAGF ^ ABC ^ BCDA ^ AGF I'm looking for algorithms for this problem. It's not absolutely important to find the strictly shortest output string, but the shorter the better. I'm looking for an algorithm better than the obvious naive one that would try appending all permutations of the input fragments and removing overlaps (which would appear to be NP-Complete). I've started work on a solution and it's proving quite interesting; I'd like to see what other people might come up with. I'll add my work-in-progress to this question in a while.

    Read the article

  • Do a query only if there are no results on previous query

    - by yes123
    Hi guys: I do this query(1): (1)SELECT * FROM t1 WHERE title LIKE 'key%' LIMIT 1 I need to do a second(2) query only if this previous query has no results (2)SELECT * FROM t1 WHERE title LIKE '%key%' LIMIT 1 basically i need only 1 row who got the most close title to my key. Atm i am using an UNION query with a custom field to order it and a LIMIT 1. Problem is I don't want to do the others query if already the first made the result. Thanks

    Read the article

  • String contains string in objective-c (iphone)

    - by Jonathan
    How can I check if a string (NSString) contains another smaller string? I was hoping for something like: NSString *string = @"hello bla bla"; NSLog(@"%d",[string containsSubstring:@"hello"]); But the closest I could find was: if ([string rangeOfString:@"hello"] == 0) { NSLog(@sub string doesnt exist") } else { NSLog(@"exists") } I typed that straight into stack so sorry if there are errors, but there would be if I was doing it in Xcode so you don't need to point any out. Anyway is that the best way to find if a string contains another string.

    Read the article

  • sample java code for approximate string matching or boyer-moore extended for approximate string matc

    - by Dolphin
    Hi I need to find 1.mismatch(incorrectly played notes), 2.insertion(additional played), & 3.deletion (missed notes), in a music piece (e.g. note pitches [string values] stored in a table) against a reference music piece. This is either possible through exact string matching algorithms or dynamic programming/ approximate string matching algos. However I realised that approximate string matching is more appropriate for my problem due to identifying mismatch, insertion, deletion of notes. Or an extended version of Boyer-moore to support approx. string matching. Is there any link for sample java code I can try out approximate string matching? I find complex explanations and equations - but I hope I could do well with some sample code and simple explanations. Or can I find any sample java code on boyer-moore extended for approx. string matching? I understand the boyer-moore concept, but having troubles with adjusting it to support approx. string matching (i.e. to support mismatch, insertion, deletion). Also what is the most efficient approx. string matching algorithm (like boyer-moore in exact string matching algo)? Greatly appreciate any insight/ suggestions. Many thanks in advance

    Read the article

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