w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Querying data results a lock on the querying table
If I'm not wrong SQL Server does not come with row versioning enabled by default, hence I think this is why you're seeing this behavior. What I suspect is when you issue a select query, and before this query finishes you issue another update query, the update has to wait until the select is complete. There are many approach to solve this problem, with one being enabling the row versioning. Other option include using the least restrictive isolation level.

Categories : Spring

Querying data from SQL
Select all the records from DB table which are f your concern Copy the select records into DataTable. Pseudo Code: --dt is datatable foreach(datarow dr in dt.rows) { --perform operation string str=dr["columnname"].tostring }

Categories : C#

Querying data table to get particular row in C#
var res = from r in dtt.AsEnumerable() where r.Field<DateTime>("StartDate") == Convert.ToDateTime(drpStartYear.SelectedValue)); select r.Field<double>("Amount");

Categories : C#

Querying Contacts with Partial Data
This technique works for me, to parse partial number, by using: //encode the phone number and build the filter URI Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number.substring(len-9))); String selection = PhoneLookup.NUMBER + " LIKE %" + number.substring(len-9) + "%"; Cursor cursor = context.getContentResolver().query(contactUri, projection, selection, null, null); Complete Example: private void getContactDetails(String number) { // define the columns you want the query to return String[] projection = new String[] { PhoneLookup.DISPLAY_NAME, PhoneLookup._ID, PhoneLookup.LOOKUP_KEY}; int len = number.length(); // encode the phone number and build the filter URI Uri contactUri = Uri.withAppendedPath(PhoneL

Categories : Android

Querying and converting data using a lambda expression
Not entirely sure I understand what you're after, but if you're looking to create a single function that returns a list of entities based on some filtering criteria, I typically do the following. First, I create a filtering object that contains all possible criteria I could filter on: public class SysLogFilter { public string Attribute1 {get;set;} public string Attribute2 {get;set;} public DateTime Date {get;set;} } Then, you pass this filter to your method and alter your query accordingly: public List<SysLog> List(SysLogFilter filter) { Entities dbContext = DAODbContext.Instance.EntitiesFactory(); IQueryable<SYSLOG> query = dbContext.SYSLOG; if(!String.IsNullOrWhitespace(filter.Attribute1)) query.Where(s => s.Attribute1 == filter.Attr

Categories : C#

Spring Data Querying DateTime with only Date
Unfortunately with JodaTime the only way around this is using the Between keyword and use two DateTime instances making up the day. interface CustomerRepo extends Repository<CustomerModel, Long>{ List<CustomerModel> findByMemberShipDateBetween(DateTime start, DateTime end); } If your domain model used Java Dates internally you could've used this style: interface CustomerRepo extends Repository<CustomerModel, Long>{ List<CustomerModel> findByMemberShipDate(@Temporal(TemporalType.DATE) Date date); } Not the @Temporal annotation is a custom Spring Data JPA one as the plain JPA one is currently not allowed on parameters. The reason that this only works with Java Dates unfortunately is a limitation of the current JPAPIs. The setParameter(…) method on Query

Categories : Java

How to avoid data caching when querying the database?
I don't know entity framework that well but I think this has something to do with change tracking. I'd try disabling it to force EF to re-query the DB, I think (and others please can correct me if I'm wrong) but unless SaveChanges has been called on an ObjectContext if you re-query the same data the database won't be queried again. I've used MergeOption = MergeOption.NoTracking (on the ObjectSet) to turn it off in my project.

Categories : Sql Server

What is a better approach of storing and querying a big dataset of meteorological data
It's a difficult question and I am not sure if I can give a definite answer but I have experience with both HDF5/pyTables and some NoSQL databases. Here are some thoughts. HDF5 per se has no notion of index. It's only a hierarchical storage format that is well suited for multidimensional numeric data. It's possible to extend on top of HDF5 to implement an index (i.e. PyTables, HDF5 FastQuery) for the data. HDF5 (unless you are using the MPI version) does not support concurrent write access (read access is possible). HDF5 supports compression filters which can - unlike popular belief - make data access actually faster (however you have to think about proper chunk size which depends on the way you access the data). HDF5 is no database. MongoDB has ACID properties, HDF5 doesn't (might be

Categories : Mongodb

Best way to prepare hierarchical data for easy querying in MongoDB?
You are locking for projection and this. Its optional operator that specifies the fields to return using projection operators and it's boolean 1 - show & 0 - hide db.customers.findOne({"users.mail": "mail@address.org"}, {users: 1}) That's not secure to use findOne({"users.mail": "mail"}) for authentication, there is special Node.js module PassportJS.

Categories : Mongodb

Querying data from tables having one-to-many and many-to-one relationships based on the relationship
I hope I understood you correctly. For each Agency you want to know how many of each type of unit (learner, facilitator, course) there are. This query should do what you want to do: ;WITH data AS (SELECT T1.*, T2.FULLNAME AS Facil_Name, T3.ID AS Learner_Name, T4.AGENCYNAME FROM COURSES T1 INNER JOIN FACILITATORS T2 ON T1.FACILITATORID = t2.ID INNER JOIN LEARNERS T3 ON T1.ID = T3.COURSEID INNER JOIN AGENCIES T4 ON T1.IMPLEMENTINGAGENCYID = T4.ID) SELECT AGENCYNAME, Count(DISTINCT FACIL_NAME) Per_Agency, 'Facil' TYPE FROM data GROUP BY AGENCYNAME UNI

Categories : Dotnet

PHP Best Practices for querying a group of class objects with summarized data
There are a number of tasks to be done and, yes, some of them are specific to each class. Especially when it comes to knowing which columns there are and how to treat them. But on the other hand there is the abstract logic of 'grouping something' and of building search patterns (and this includes of course also a range of date handling functions). These two can/should be placed in separate objects/functions which can be called from both classes, orders and invoices. A similar thing goes for putting together the result arrays. Here we need to be able to adapt to all sorts of different grouping conditions. The column names are class specific but the general logic can be put in separate classes or functions.

Categories : PHP

Querying a PostgreSQL multi-dimensional array data type in Rails 4
I am using a PostgreSQL multi-dimensional array to mimic an array of hashes Those two things aren't really all that similar, and I wouldn't recommend attempting to use multidimensional arrays to model nested hashes. Pavel is quite right that hstore is probably a lot closer to what you want, and it's indexable too. However, the current version of hstore (in Pg 9.3 and older) supports only single-level keys; it's a dictionary/hash that can contain only scalar string values. A planned enhancement to hstore for PostgreSQL 9.4 will hopefully bring multi-level nesting and JSON syntax compatibility. Ordinary tables You can model arbitrary-depth key/value chains(and trees/graphs) using edgelists and recursive CTEs, but this probably rather more complexity than you really want. If you only

Categories : Postgresql

Rails 4 querying against postgresql column with array data type error
I don't think that it has related to rails. What if you do the follow? SELECT * FROM db_of_exercises WHERE 'Arms' = ANY (body_part) OR 'Chest' = ANY (body_part) I know that rails 4 supports Postgresql ARRAY datatype, but I'm not sure if ActiveRecord creates new methods for query the datatype. Maybe you can use Array Overlap I mean the && operator and then doind something like: WHERE ARRAY['Arms', 'Chest'] && body_part or maybe give a look to this gem: https://github.com/dockyard/postgres_ext/blob/master/docs/querying.md And then do a query like: DBOfExercise.where.overlap(:body_part => params[:body_parts])

Categories : SQL

Web page render fails when querying large amount of data from mysql using node.js
You are probably not missing much, and it probably is the timeout you mention. It really depends on how you want your client to behave: 1) You could increase the client's timeout (maybe it's an internal application, and it's OK to increase? Maybe it's an XHR object and you can control the timeout, let it wait "in the background" while the user is busy doing other things on the page?). 2) You could change the client-side code to do this in the background, updating the DOM once it gets the results. 3) You could have a server-side queue with the results, immediately returning to the client a "job id" and let the client poll on it. Or maybe use "comet" and send a notification to the client once the job is complete. As I said, you really need to define how you want your client to behave.

Categories : Mysql

RavenDB OrderBy
If you are using an index you need to set the sortoptions for the Order property. From http://ravendb.net/docs/client-api/querying/static-indexes/customizing-results-order Numerical values, on the other hand, are stored as text and therefore require the user to specify explicitly what is the number type used so a correct sorting mechanism is enforced. This is quite easily done, by declaring the required sorting setup in SortOptions in the index definition: Sort(x => x.Order, SortOptions.Int); The index outlined above will allow sorting by value on the user's age (1, 2, 3, 11, etc). If we wouldn't specify this option, it would have been sorted lexically (1, 11, 2, 3, etc). The default SortOptions value is String. Appropriate values available for all numeric types (Byte, Doub

Categories : C#

OrderBy on a Sub Collection using RavenDB
result.OrderBy(x => x.Field.Name) will return a collection as LINQ will not change the collection on which it is called rather it returns a new collection which has the required result. So do result = result.OrderBy(x => x.Field.Name);

Categories : C#

RavenDB indices chains
Yes. You can now do this. Enable the Scripted Index Results bundle Write your first index, for example - a map/reduce index. Write a script that writes the result back to another document. Write a new index against those documents. As changes to the original documents are indexed, the resulting changes get written to new documents, which then get indexed. Repeat if desired, just be careful not to create an endless loop. This is a new feature for RavenDB 2.5. Oren describes it in this video at 21:36.

Categories : C#

RavenDB domain error
Connecting locally, are you using http://localhost:[port]? I've had problems using the domain name locally. Try running your application locally and connect to the RavenDB via locahost address.

Categories : Windows

RavenDB polymorphic Index
What are you trying to do? If the end result is to query all Principals, then load the entire User or AppInstance, why not just go straight for querying all Users or all AppInstances? Raven won't store base classes; it will only store the most derived type (User or AppInstance, in your case). So you'll have a collection of Users and a collection of AppInstances. If you really need to query both at once, you can use Multi Map indexes. You can also change the entity name and store both in a single Principal collection. But it's difficult to recommend a solution without knowing what you're trying to do. Explain what you're trying to do and we'll tell you the proper way to get there.

Categories : C#

Load all documents from RavenDB
I figured it out: I have to wait for non staled results. So if I change my Query out with this: session.Query<Model.Category>().Customize(cr => cr.WaitForNonStaleResults()).ToList(); it works just fine.

Categories : C#

Ravendb Array intersect
The Array intersection is not allowed, but you can write your query as follows: var colors = session.Query<Color>() .Where(c => c.colorArray.Any(x => x == "r") && c.colorArray.Any(x => x == "e") && c.colorArray.Any(x => x == "d")); Please note that in order for this to work, you need to use strings, not chars. The colorArray property in your Color class needs to be defined as: public string[] colorArray { get; set; } The reason is that if you use char[], then the query will check for the numeric values (ASCII codes) rather then the string values (ex: 'r' will be interpreted by the query engine as 114, 'e' to 101 and 'd' to 100). Now, to take this

Categories : Arrays

Nservicebus 4 with azure and RavenDB
You have 2 options: Use RavenHQ and assign the connection string, see http://support.nservicebus.com/customer/portal/articles/859362-using-ravendb-in-nservicebus-%E2%80%93-connecting Use SqlServer as persistence

Categories : Azure

Error in selecting value from RavenDB
If you try to instanciate var ctrl = new Activation(); and do ctrl.validate(x); it won't work as OnActionExecuting didn't run. That function is called automatically by the MVC framework when serving a request, not when manually testing. Since MVC instantiates a new controller on each requests anyway, you should move the RavenSession initialization to the constructor since you do not seem to use any info in the request context: public class RavenBaseController : Controller { public IDocumentSession RavenSession { get; protected set; } public RavenBaseController() { RavenSession = MvcApplication.Store.OpenSession("ravendbtesting"); } protected override void OnActionExecuted(ActionExecutedContext filterContext) { if (filterContext.IsChildAction) retu

Categories : C#

Bulk insert in RavenDB
You should probably not be upserting one record at a time. RavenDB has a bulk insert feature that will make things much easier and faster. See http://ravendb.net/docs/2.0/client-api/advanced/bulk-inserts

Categories : C#

RavenDB get ID of newly stored document
The Id property of the Product class must be of type string instead of integer. Then you will be able to retrieve the autogenerated id after the operation: Product p = new Product() { Title = "My Fancy Product" }; RavenSession.Store(p); string id = p.Id; More information can be found in the documentation (Document IDs section): In the example above we had a string Id property for BlogPost, and left it blank. It is this property that will be used as the "primary key" for this document. Note how RavenDB generated an ID for us, "BlogPosts/1", based on the default convention which we will discuss in a second. If there is no Id property on a document, RavenDB will still generate a unique ID, but it will be retrievable only by calling session.Advanced.GetDocumentId(objec

Categories : C#

Custom Field Design with C# and RavenDB
Since you said in comments: ... a Book from a year ago should show the custom fields as of a year ago. There are only two viable options I can see. Option 1 Custom field definitions exist in their own documents. Every book contains a copy of the custom field definitions that apply to that book, along with the selected values for each custom field. They are copied when the book is first created, but could be copied again as your logic sees fit. Perhaps on edit, you might want to take a new copy, potentially invalidating the current selections. Advantages: Self-contained, easy to index and manipulate. Disadvantages: Lots of copies of the custom field definitions. Storage requirements could be very large. Option 2 Use the Temporal Versioning Bundle (disclaimer: I am its author

Categories : C#

RavenDB Query does not return all records
By default, queries return up to 128 records. Use an explicit Take(n) to get more records.

Categories : C#

RavenDB LoadAsync. Can't catch exception
The behavior your seeing is valid, and is not because you couldn't catch the exception. It's because the exception was already caught for you. In RavenDB, if you try to load a document that doesn't exist, the Load or LoadAsync methods will return null. They will not throw an exception. When you are debugging, you are seeing that under the hood a WebException is thrown when the HTTP response comes back as 404. That exception is handled. You should see it in the output window as a "First Chance Exception". This is all normal behavior. If you want to check that you can catch exceptions, try something that will actually throw an exception. Perhaps load a document of one type while trying to cast it into another. That will certainly throw an exception.

Categories : C#

RavenDB - wait for document creation
Well, I'm not sure what mechanism you are using for event processing, but I have been in a similar situation with something like NServiceBus. I don't think this exactly a RavenDB problem. You would probably have the same issue if you were writing to a SQL Server database. The generalized problem is, Create and Update events are fired off, but they are received and processed in the wrong order. What to do? Well the general advice is that your event handlers should be idempotent, and should retry when failed. So if Update is received first, it will throw an exception and be scheduled for retry. Then Create comes through, then Update retries and all is good. Specifically blocking and waiting in the handler for the Update event is not advised, because if you had several of these then t

Categories : C#

Multiple tests running with RavenDB
Assuming that Controller.Post(testString) is adding a new entry, you probably just have a stale index. In the real world, some natural amount of time would pass between post and query. In unit tests, you don't have that delay, so it's common to provide the following on your index: .Customize(x => x.WaitForNonStaleResults()) This is not something you should do in production. You can read more in the documentation here.

Categories : C#

RavenDB Query Always Faster Than Load
From what I understand, Load will guarantee to return a result (provided that id exists in the database) whereas Query might not return a result if the indexes haven't yet been updated. You could have a scenario whereby you insert a record, then on the next line try to retrieve that same record using Query and then not get anything back. Load would return a record in this scenario. So I guess the performance degradation you are seeing might be related to the fact that you are querying by index when using Query, whereas Load is hitting the actual data store.

Categories : C#

RavenDB DocumentStore in Class Library
You will have to reference RavenDB from the class library, you can't really go around that. You may find the following article insightful, though: http://novuscraft.com/blog/ravendb-and-the-repository-pattern

Categories : C#

Can RavenDB persist documents to a filesystem?
You don't need RavenDB for that. Just use System.IO.File and related concepts. Raven won't work with individual files on disk. It keeps it's own set of files for its index and data stores. Access from other programs is not allowed. What happens in RavenDB, stays in RavenDB. Most people store big files on disk, and then just store a file path or url reference to them in their RavenDB database. Raven also supports the concept of attachments, where the file is uploaded into Raven's database - but then it wouldn't be available as a single file on disk the way you are thinking.

Categories : File

Where should I place business logic when using RavenDB
There's two main parts to consider here. Firstly, as you have already noted, if you go by the word of the more fanatical RavenDB fans it is some mythical beast which is exempt from the otherwise commonly accepted laws of good application design and should be allowed to permeate throughout your application at will. It depends on the situation of course but to put it simply, if you would structure your application a certain way with something like SQL Server, do the same with RavenDB. If you would have a DAL layer, ORM, repository pattern or whatever with a SQL Server back-end, do the same with RavenDB. If you don't mind leaky abstractions, or the project is small enough to not warrant abstracting your data access at all, code accordingly. The main difference with RavenDB is that you're g

Categories : C#

how to inject ravendb instance through IDatabaseFactory interface?
If your Raven client does not have the interface already you will need to craft it yourself. You will need to make a factory instance implementing all of the members on that interface and pass it across.

Categories : C#

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#

RavenDB - How do I query on both an object's properties and its children
First, we'll tackle the index, note that child keys are prefixed with Children_ (required by Raven): public class Objekt_ByCodeAndChildren : AbstractIndexCreationTask<Objekt> { public Objekt_ByCodeAndChildren() { Map = objekts => from objekt in objekts from child in objekt.Children select new { objekt.Code, Children_Role = child.Role, Children_Place = child.Place }; } } The query itself: session.Query<Objekt, Objekt_ByCodeAndChildren>() .Where(o => o.Code == "1" && o.Children.Any(c => c.Role == "A" && c.Place =

Categories : C#

RavenDb Constucting complex viewmodel using MultiMap?
The best idea here would to not have them as separate documents. A single document can contain all of this. In other words, the structure you've described as the view model can be stored directly into the database as your document structure. Of course, that means that you will always be retrieving the document by the top-level id. Without additional context of what these nodes represent, it's hard to say if that is appropriate or not. Also, it looks like you are getting good feedback from this thread on the RavenDB Google Group already. Try not to cross-post in the future. If you want something very specific, then StackOverflow is great. If you need more of a general how-to or debate of ideas, then use the Google Group. If you can edit your question to be more specific, perhaps sh

Categories : C#

Query over a collection of composite keys in RavenDB using C#
There are multiple ways to do this, but the easiest way would be to provide your own document key instead of using the one Raven generates. This is often referred to as using "structured" or "semantic" keys. Here is a good description of the general technique. Simply add a string Id property to your class. You want the document key to reflect the unique key you described, so probably it should have a value such as "reports/2013/Q1/bob" (but you might want a more unique value for user). You can let .Net construct the key for you in the property getter, such as: public class Report { public string Id { get { return string.Format("reports/{0}/Q{1}/{2}", Year, Quarter, User); } } public string User { get; set; } public int Quarter { get; set; } public int

Categories : C#

RavenDB Query on Inner property serialize with [JsonProperty]
This appears to be a bug in the query provider for DocumentSession.Query<> where it will not honor the Newtonsoft attributes on documents. However if you use the Lucene query provider it will perform as expected: [Test] public void Test() { using (var session = DocumentStore.OpenSession()) { session.Store(new Parent {Inner = new Child {Num = 1}}); session.SaveChanges(); } using (var session = DocumentStore.OpenSession()) { var list = session.Advanced.LuceneQuery<Parent>() .WhereEquals(x => x.Inner.Num, 1) .ToList(); Assert.That(list.Count, Is.EqualTo(1)); } }

Categories : C#



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