w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Can't add keys with dots (key paths) to a Mongoose field with type: Schema.Types.Mixed
Yes, it is. Valid JSON doesn't have dots as far as I know. What you are supposed to do is this: { "character": { "treasure_chests": 1 } } Here is an example: JSON Schema example

Categories : Json

Query to return rows in date range but return only max value of column
Using the row_number() function to rank the rows select product, price, version from ( select *, row_number() over (partition by product order by version desc) rn from yourtable where @dategiven between startdate and enddate ) v where rn = 1

Categories : SQL

Mongodb return documents AND the array elements that match query
Yes, the aggregation framework will help you do this. Something like this query should work: db.collection.aggregate( { $unwind : "$list" }, // deconstruct the array { $match : { list : { $gt : 100 } } }, // match based on your condition { $group : { _id : "$_id", list : { $push : "$list" } } } // rebuild array ) You'll have to change this query based on your exact data structure, but that's the general idea.

Categories : Mongodb

Apply function to field on all documents returned from MongoDB query in nodejs
The proper way, I believe, would be to add a truncatedBody property to your Article, and implement the truncate method as a static: Article.methods.setTruncatedBody = function(limit){ //If truncatedBody is already computed, don't do anything if(this.truncatedBody) return; var value_arr = body.split( ' ' ); if( limit < value_arr.length ) { this.truncatedBody = value_arr.slice(0, words).join( ' ' ); } else this.truncatedBody = body; } Then, in your controller: Article.find({}) .sort({'meta.created': 'desc'}) .limit(6) .exec(function(err, articles) { for(var article in articles) article.setTruncatedBody(5); res.render(articles: articles}); });

Categories : Node Js

Query on Junit @parameters method's return type and the test class constructor argument type
As you suggested the values are being casted. The casting is actually done by the Java reflection API, specifically: Constructor.newInstance(Object...). If you're curious, the above method is invoked by JUnit on line 186, here (JUnit v4.11 source).

Categories : Java

python: query a DATETIME field in a sqlite db for a date range
You can do a query like this: SELECT * FROM Table where date >= date('now', '-60 day'); EDIT: Based on your actual query: select <field1>, <field2>, count(1) as num FROM Table where date >= date('now', '-60 day'); group by <field1>, <field2>; SELECT DISTINCT is unnecessary when you are using GROUP BY.

Categories : Python

Mongodb index doesn't use one bound in range query
The problem with using both index bounds is that a document could have one eDate that satisfies the $gt and another eDate that satisfies the $lt. Because the sematics of your query would match that document it must look at more docs than it would if it used both index contstraints. There are to things that can help in these types of cases: $elemMatch (see http://docs.mongodb.org/manual/reference/projection/elemMatch/) and cursor.min / cursor.max (http://docs.mongodb.org/manual/reference/method/cursor.min/).

Categories : Mongodb

ROWNUM doesn't work; trying to grab info on specific row range in SQL query
You need to understand the meaning of that AUTO_INC thingy. It is called an unique identifier, and for a reason. "Unique" means no other row should have the same identifier ever. Yet it has absolutely nothing to do with whatever enumeration. So - I have an autoincrementing column titled 'updateno' which corresponds to the number of the row. this is what you are doing wrong. As a matter of fact, you don't need such a field at all. If you wnat to enumerate your fields - do in on the fly. If you want an identifier - use a conventional name for this - "id" While for the whatever "rownum" feature you need another mysql operator, namely LIMIT

Categories : PHP

How to query a field with ASCII 13 or "Carriage return"?
SELECT * FROM Table1 where Myfield = Chr(13) I might also look for a limited number of characters SELECT * FROM Table1 WHERE Myfield = Chr(13) OR Len(Myfield) < 2 ' or < 3

Categories : SQL

Why doesn't my mysql query in php return more than one row?
$_UserData['Fname'] = $SQLRow['Fname']; $_UserData['Lname'] = $SQLRow['Lname']; You're repeatedly setting the same two elements of _UserData, rather than appending new values to the array.

Categories : PHP

How to find documents that has field some field empty in solr 4.3.1
For type string, I had 2 documents - One with <str name="gender"/> The other with <str name="gender">male</str> When I query with: http://localhost:8080/solr/mycore/select?q=gender%3A%22%22&wt=xml&indent=true I get the document where gender is empty. Isn't that what you want? On the other hand, to get the document where it is not empty, I used this: http://localhost:8080/solr/mycore/select?q=gender%3A%5B%22%22+TO+*%5D&wt=xml&indent=true

Categories : Solr

mongoid query, select more field return in json
Did you mean only(:title => "abc") is to select only field "title" ? Then, the solution may be replacing it with only(:title) If what you mean only is where title is "abc" then replace only(:title => "abc") by where(:title => "abc") to_json should work then.

Categories : Ruby

Why my query doesn't return any results from RavenDB?
You should check that the index "Raven/DocumentsByEntityName" is defined for the target database, and that your document has the correct metadata information. The metadata should have a line like this: "Raven-Entity-Name": "CountryRegion" If this does not help, please also post the ravendb version you are using. A fiddler trace might also be helpful.

Categories : C#

How can i return '0' from query in pgsql, if the row doesn't exist?
SELECT CASE WHEN EXISTS (SELECT 1 FROM table WHERE xxx) THEN 1 ELSE 0 END But your question talks about exists on a field not on a row. If you're just comparing to NULL, and considering that "if it exists", it'd be: SELECT CASE WHEN field IS NULL THEN 0 ELSE 1 END FROM table (And of course, if you actually want '0' the string, just put single quotes around the return values.

Categories : Postgresql

Weird error using Rhino Mocks "type doesn't match the return value"
If you're trying to mock IInterface then you're stubbing the wrong method: public void RunThis() { var stubReader = MockRepository.GenerateStub<IInterface>(); stubReader.Stub(sr => sr.GetDecimal()).Return(1.2); } If you're trying to stub DecToDouble, you can't with RhinoMocks. Extension methods are compiled to static method calls which can't be mocked by RhinoMocks because they're bound at compile-time. Some stub frameworks use low-level profiler calls to intercept static calls but RhinoMocks does not have that capability that I know of. See this question for a similar discussion.

Categories : C#

Function returning TCHAR * type vector doesn't return it correctly
You are storing pointers to a variable that is local to the for loop. It seems to work the first time because you are in the same iteration but really this is just lucky. Returning a pointer or a reference to a scope local variable is not something you can do in C++. You should either dynamically allocate the TCHAR* array and store unique_ptr in the vector or use strings instead. TCHAR szModName[ MAX_PATH ]; This variable here gets overwritter at every iteration. P.S: void main is non-standard, please use int main.

Categories : C++

return query result only if value of field on associated model is not empty cakephp
You should always check the queries that are executed by CakePHP. By enabling debug level 2, the SQL statements should be visible on your page. In your case, I suspect the NOT NULL condition is not specified correctly. It should probably be like this; $this->ModelA->find('first', array( 'contain' => array( 'Model B' => array( 'conditions' => array( 'NOT' => array( 'ModelB.number' => NULL ) ) ) ), 'conditions' => array( 'ModelA.id' => 13 ) ));

Categories : PHP

Query doesn't return empty Brand fields
I was able to retrieve the records with a right join. Access kept complaining that putting an outer join where I have the right one was a syntax error. It appears access should use Outer joins as I read from the docs here http://office.microsoft.com/en-us/access-help/creating-an-outer-join-query-in-access-HA001034555.aspx SELECT Review.ID, Review.Claim, Review.Consultant, Review.TSO, Review.[Claim Review Date], Review.[Discussion Point], Review.[Review Notes], Review.[Review Decision], Brand.Brand, Categories.Reason, [TSO Leader].LeaderName FROM [TSO Leader] INNER JOIN (Categories INNER JOIN (Brand RIGHT JOIN Review ON Brand.BrandID=Review.Brand) ON Categories.CategoriesID=Review.Categories) ON [TSO Leader].LeaderID=Review.[TSO Leader];

Categories : SQL

Is there any way that I can alter this SQL query so that it doesn't return any results containing whitespace?
To ignore white spaces, you can try WHERE NOT LIKE '% %' This will perform the same as INSTR.

Categories : Mysql

Need query to return zero when count(*) doesn't match any records
Hard to understand what you want, but select decode(count(*), 0, null, count(*)) will return null when there are no records in the group. UPDATE: Now is clearer what you want: select date_code, cnt from( select trunc(sysdate-10) + level - 1 as date_code from dual connect by level <= 10 ) left join( SELECT COUNT(*) cnt,TRUNC(TEST_DATE_CREATE) trunc_create FROM TEST_TABLE WHERE TEST_DATE_CREATE > (SYSDATE - 10) GROUP BY TRUNC(TEST_DATE_CREATE); ) on trunc_create = date_code UPDATE2: Now is clearer what you want, zeroes not nulls: select date_code, count(*) from( select trunc(sysdate-10) + level - 1 as date_code from dual connect by level <= 10 ) left join TEST_TABLE on TRUNC(TEST_DATE_CREATE) = date_code GROUP BY date_code

Categories : SQL

Salesforce databasedotcom gem: Query doesn't return right results
I recently ran into a very similar issue using Twitter and Oauth. Are you using a global configuration of some sort? Check out the Thread safety section here: https://github.com/sferik/twitter#thread-safety I think it might be relevant.

Categories : Ruby On Rails

Why doesn't ChangeListener's getSource() return a pre-cast object of the type used to generate an event?
The fact that the source will be a JSpinner is known at runtime. The kind of “automatic type casts” you describe are possible with generics at compile time, but at that time there is no telling where the listener might end up. For example, you could take your spinner, obtain a list of all listeners, and then add these listeners to another widget like a check box. There is nothing in your code to tell the compiler at compile time that this won't happen, so there is nothing to tell the compiler that the source will always be a spinner. It would theoretically be possible to use generics in some way. You could have a ChangeEvent<T> for changes originating from a component of class T. You could have a ChangeListener<T> with a method stateChanged(ChangeEvent<? extends T>).

Categories : Java

Facebook FQL query event doesn't return correct result
This seems to be a bug, I filed it for you here: https://developers.facebook.com/bugs/653769257984873 you can subscribe to follow it.

Categories : Facebook

PHP mySQL query not working with variable as in field for SQL TIME type
You're missing single quotes around $stime in your second query : $stime = '06:00:00'; $result = $wpdb->get_var($wpdb->prepare("SELECT * FROM table WHERE start_hour='$stime'", ARRAY_A));

Categories : PHP

query custom post type by advanced custome field value
Did you try to use 'life_style' => 'firsthome', instead of 'meta_query' => array ( 'key' => 'life_style', 'value' => 'firsthome' ) meta_query is not in class reference of query_posts

Categories : Wordpress

PDO Database doesn't return rows, only returns query string (pdo object)
Here are a few findings that you might find useful. First is from the PHP manual on PDO::prepare. But you are passing a single string using implode(), but I think this is still something important to keep in mind. You cannot bind multiple values to a single named parameter in, for example, the IN() clause of an SQL statement. Second and third are probably due to typo: $sql = "SELECT img_link, img_thumb "; // this semi colon will cause syntax error on the next line. .= "FROM mycars_gallery WHERE car_id = :carid AND id IN(:imgids);"; and, in your table structure you've shown mycar_id as a column but you have car_id in your where clause. Finally, possible solution which I didn't want to copy paste, so here is something you could implement to solve the in issue: PHP PDO: A

Categories : PHP

perl return values from sub get mixed up
Perl is merging your two hashes into one and storing them in your %r1 variable, this will always happen unless you return references from your subroutines. sub sub1 { my (%h1, %h2); $h1{'1a'}++; $h1{'1b'}++; $h2{'2a'}++; $h2{'2b'}++; while ( (my $key, my $value) = each %h1 ){ print "key: $key, value: $value "; } print " "; return (\%h1, \%h2); # (backslash) creates a hashref } Then you need to store those references in scalar variables: my ($r1, $r2) = sub1(); # scalar variables with references to %h1 and %h2 # use %{ } to put $r1 in hash context while ( (my $key, my $value) = each %{ $r1 } ){ print "key: $key, value: $value "; } # prints # key: 1b, value: 1 # key: 1a, value: 1 # key: 1b, value: 1 # key: 1a, value: 1

Categories : Perl

left join doesn't return the rows without corrispandednt in the second table(right) when i use COUNT in the query
COUNT() is an aggregate function the count non-NULL values. See http://dev.mysql.com/doc/refman/5.1/en/counting-rows.html Since you do not have GROUP BY clause, use a aggregate function like COUNT() is probably not what you want. You should either add the missing GROUP BY clause: SELECT users. * , COUNT(user_bets.id) as bets FROM `users` LEFT JOIN `user_bets` ON `user_bets`.`user_id` = `users`.`id` GROUP BY `users`.`id` Or perhaps use IF(...): SELECT users. * , IF(user_bets.id IS NOT NULL, 1, 0) as bets FROM `users` LEFT JOIN `user_bets` ON `user_bets`.`user_id` = `users`.`id` See http://sqlfiddle.com/#!2/08a52/3 to experiment with that.

Categories : Mysql

Custom field in SQLite SELECT query doesn't become DateTime column in DataTable after filling it?
Our team at work have been researching this issue for a long time. Our final conclusion is that any expression wrapping source field makes source data type unavailable. For ADO.NET providers using of expressions leads to System.Object final type, for ODBC provider it leads to System.String type. So it completely depends on data provider you use. Why does it behave in such way is a question to data provider developers (I haven't found the answer). By the way, .NET Framework provides a variety of tools to test whether given value is of type expected. There are only 5 basic data types in SQLite 3 (NULL, INTEGER, REAL, TEXT, BLOB). So in .NET code you can pass your value through the test for 3 most common types (INTEGER, REAL, TEXT).

Categories : C#

Blade mixed with PHP doesn't work
Instead of using <? and ?> , use <?php and ?>, That made me suffer back in my CodeIgniter days. I'd also prefer using the foreach loop the blade way. @extends('base') @section('title', 'Quests') @stop @section('main') <?php $quests = array ( 1 => array ( "name" => "Quest 1", "level" => 100, "description" => "Write your description here", "reward" => "Shield, Boots"), 2 => array ( "name" => "Quest 2", "level" => 100, "description" => "4 Peoples needed!", "reward" => "Sword, Stonecutter Axe, Armor, Present(choose 1)"), 3 => array ( "name" => "Inferno Quest", "level" => 100, "description" => "Very hard quest. You need a big team to do this quest, the quest is long too!", "reward" => "bla bla") ); ?> <div

Categories : Laravel

what should be return type of a query which fetches 2 columns in spring data neo4j?
In that case queries return an Iterable<Map<String,Object>> which allows you to iterate over the returned rows. Each element is a map which you can access by the name of the returned field and using the neo4jOperations conversion method to cast the value object to its proper class, i.e.: Iterable<Map<String, Object>> it = getNodes(...); while (it.hasNext()) { Map<String, Object> map = it.next(); obj = neo4jOperations.convert(map.get("member"), Node.class); ... }

Categories : Java

Mixed managed C++ method does not always return the same result to the calling C# code
You seem to be calling a lot of methods you haven't listed, and/or the wall of code made me get lost. Adding that code won't help: reducing your problem to a simpler one that demonstrates the problem might. However, the most likely cause of your problem, if you have unmanaged code reading managed data, is that you failed to marshal or pin the data prior to using the managed code. Unpinned data can be moved around by the garbage collector in unexpected ways.

Categories : C#

Setting Mixed Schema Type Error
Moral of the story: don't used Mixed types. But seriously, I never did figure out what this particular issue was. I ended up just updating to the latest version of Mongoose and dealt with the errors as they came in (mostly API changes). The logs were changed before that to not include any Mixed data.

Categories : Javascript

setting date range of one field depending on input of another field jquery datepicker
Working JS FIDDLE you need to pass in selectedDate to your event handler, and then convert it to a date object, and then add the 4 days and the seven days. also, your better off using the custom event handlers built specifically for the datepicker to handle events for it, onClose rather than a default one you'll have to build out code for. here is the code from the fiddle: $('#apply').datepicker({ showOtherMonths: true, selectOtherMonths: true, minDate: 0, maxDate: "2m", onSelect: function(selectedDate){ console.log(selectedDate); $('#last').prop('disabled', false); $('#last').datepicker({ minDate: (function(){ var min = new Date(selectedDate); var newmin = new Date(); newmin.setD

Categories : Jquery

Saving mixed schema in mongoose (markModified doesn't seem to work)
The save method is asynchronous, which means you can't be sure it has finished its work the way you write your code now. Use callbacks: results[0].save( function(error){ if (error){ // augh! }else{ console.log(results[0]); // <- yay! the document is definitely saved here // ... } }); //console.log(results[0]); // <- no, we can't be sure results[0] is already saved in this line

Categories : Mongodb

Omitting the return type in abstract method, but not in abstract field
It's drop-dead simple. If you omit the return type of an abstract method, then Scala compiler will infer it as a Unit (after typer phase): abstract trait Some extends scala.AnyRef { def method: Unit; <stable> <accessor> def field: String }

Categories : Scala

Printing a mixed type dictionary with format in python
You can use round for rounding the floats to a given precision. To identify floats use isinstance: >>> {k:round(v,2) if isinstance(v,float) else v for k,v in d.iteritems()} {'a': 'Ali', 'p': 3.14, 'c': 0.24, 'b': 2341} help on round: >>> print round.__doc__ round(number[, ndigits]) -> floating point number Round a number to a given precision in decimal digits (default 0 digits). This always returns a floating point number. Precision may be negative. Update: You can create a subclass of dict and override the behaviour of __str__: class my_dict(dict): def __str__(self): return str({k:round(v,2) if isinstance(v,float) else v for k,v in self.iteritems()}

Categories : Python

Sending an email: no object DCH for MIME type multipart/mixed
I think it's a classloader issue to do with the way GroovyConsole runs... If I add the following @Grab and @GrabcConfig to the script, it works... @Grab( 'javax.mail:mail:1.4.7' ) @GrabConfig(systemClassLoader=true, initContextClassLoader=true) import javax.mail.* import javax.mail.internet.* import javax.activation.* def props = new Properties().with { p -> p.'mail.smtp.host' = 'my mail server' p } def session = Session.getDefaultInstance( props ) def message = new MimeMessage( session ) message.addRecipient( Message.RecipientType.TO, new InternetAddress( 'to address' ) ) message.subject = 'This is the subject' message.text = 'This is the message #1' message.from = new InternetAddress( 'from address' ) def textpart = new MimeBodyPart() textpart.text = 'This is the messa

Categories : Groovy

How can a mixed data type (int, float, char, etc) be stored in an array?
You can do a void * array, with a separated array of size_t. But you lose the information type. If you need to keep information type in some way keep a third array of int (where the int is an enumerated value) Then code the function that casts depending on the enum value.

Categories : C

Search by field in a referenced documents
You cannot join collections together in mongodb itself. Instead you either need to structure your DB design so that say in the example, user_relations would be an attribute of users. Or- perform the join effectively in the client app once you have the keys / _ids of the users you want to fetch. Because you can't perform these joins on the server, it really forces you to consider exactly what information you want to return. You could easily pass an array of user _ids you want to return and use the $in operator to return a set of user documents. Hope that helps.

Categories : Mongodb



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.