w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Presenting a collection view as a subview works, but presenting it by a collection view controller fails when a cell should be dequeued
I solved my problem, but I am not happy with it. First I simplified my code. When I set up the collection view controller, I now only create the layout and the controller, and then present it. This is possible according to the docs, "If you create the collection view controller programmatically, it automatically creates a new unconfigured collection view object, which you can access using the collectionView property." I assumed that I can access the collectionView property of the collection view controller already in the viewDidLoad method of this controller, but this is not the case. Apparently, the first time I can access it is in the data source callback collectionView:numberOfItemsInSection: which gives me the actually used collectionView object. Therefore I can only there register my

Categories : IOS

How do I get active rows in 1 to many relationship using Linq?
You could try this: return r.Find() .Include("MatchNodes.MatchBuyer.Buyer") .Where(c => c.MatchNodes .Any(c => c.Enabled == true && c.MatchBuyer.Buyer.Status == "Active") ) .ToList(); It will give you all the Tiers that has MatchNodes.Enabled == true and Buyer.Status == "Active" EDIT To only return the MatchNotes use a SelectMany: var lst = r.Find() .Include("MatchNodes.MatchBuyer.Buyer") .Where(c => c.MatchNodes .Any(c => c.Enabled == true && c.MatchBuyer.Buyer.Status == "Active") ) .SelectMany(c => c

Categories : Linq

Copy rows from one table to another and make a relationship of many to many
Assuming that ID is an identity in users and that the admin role exists in roles and there are no existing users, something like insert into users( name ) select name from ImportUsers insert into UsersToRoles ( UserID, RoleID ) select users.id , role.id from users, roles where role.name = 'admin'

Categories : Sql Server

I have a OneToMany relationship between A to B. But when I do getB() I don't get multiple rows
When you plan to add objects in Collections, such as Set, you must override the equals() and hashCode() methods, so that the system can compare 2 instances and detect whether they are equals. In Sets, You cannot have duplicates, so when you add an instance and another one inside the Set is equal to that instance, the second instance won't be added to the Set. An example of an equals() method with an int as id, which identify perfectly the instance (primary key): @Override public boolean equals(Object o) { if (o instanceof B) { B b = (B)o; return b.id == this.id; } return false; } And a possible hashCode() method: @Override public int hashCode() { return new Integer(id).hashCode(); } Try to learn more about these 2 methods, because they are really impo

Categories : Java

How to create a unidirectional relationship where the relationship is owned by the child entity, but the parent is where the relationship is defined
If this @OneToOne(..) @JoinColumn(name = "parent_id") private Child child; does not work, try this: @OneToOne(..) @JoinColumn(table = "child", name = "parent_id") private Child child;

Categories : Java

I found duplicate rows in SQL for a one-to-(zero or one) Entity Framework relationship - How / Why?
When you create a one-to-one relationship with Model-First Entity Framework maps it actually to a one-to-many relationship on database side. You can see that when opening the edmx file in an xml editor (you can also find it in the .Store section of the designer's model browser). In the <edmx:StorageModels> section you'll find: <Association Name="CarSpareTire"> <End Role="Car" Type="EfTest.Store.Cars" Multiplicity="1" /> <End Role="SpareTire" Type="EfTest.Store.SpareTires" Multiplicity="*" /> <ReferentialConstraint> <Principal Role="Car"> <PropertyRef Name="Id" /> </Principal> <Dependent Role="SpareTire"> <PropertyRef Name="Car_Id" /> </Dependent> </ReferentialConstraint> </Associ

Categories : C#

Inserting multiple rows into SQL Server 2008 table, copied from other rows with one column changed
Use a cross join. You didn't say what version of SQL you were using, so I'll low-ball it: INSERT INTO TableName( Column1, Column2, Column3, Column4, Column5, Column6) (SELECT Column1, Column2, Column3, Column4, Column5, a.[sc] FROM TableName as t cross join ( select 'NewShopCode1' as [sc] union select 'NewShopCode2' as [sc] union select 'NewShopCode3' as [sc] ) as a WHERE Column5 = 'DistinguishingValue' and not exists (select 1 from TableName as t where t.Column1 = a.Column1 and t.Column2 = a.Column2) ) Try the select by itself to see that it produces the correct results before inserting.

Categories : Sql Server

Restrict the rows retrieved from database for the relationship between the domain classes
In this case you can use criteria to do that: Entity.createCriteria().get { eq('id', 0) projections { titles { eq('isActive', true) } } } I don't think it's possible to set a default where to be applied in all your database calls to that Domain Class. You can also wrap your logic in a service: class EntityService { def get(Long id) { return Entity.createCriteria().get { eq('id', id) projections { titles { eq('isActive', true) } } } } }

Categories : Grails

Two tables, whit one to many relationship. How to join values without duplicate rows?
Unfortunately you cannot do this purely in MySQL. In the result set you can't have rows with different (number of) columns. You need some application logic implemented. The closest you can get to this is: select m.id, GROUP_CONCAT(voto SEPARATOR ',') from messages m left join votations v on v.messageID = m.id group by m.id; This will return this format: ID GROUP_CONCAT(VOTO SEPARATOR ',') 1 2,5,6 2 2,12,3 You can see this working here: http://sqlfiddle.com/#!2/241a8/3

Categories : Mysql

Hibernate/JPA 2.0 @OneToOne relationship with possibly non existent matching rows
This is known bug: HHH-4982 (JPA OneToOne(optional=true) not supported with @PrimaryKeyJoinColumn). Problem can be solved by updating to newer version. Bug is fixed in 3.6.8, but likely it makes sense to update to 3.6.10, if going for Hibernate 4 is not an option.

Categories : Hibernate

EF - One to one optional relationship + SQL Server cascade
This is very strangely named. I'm not very fit in EF, but I gather that you want many (or zero or one) FinanceiroLancamentoCaixa records for each FinanceiroLancamento record. The normal way to do this in SQL would have an Id column in both tables plus a "IdFinanceiroLancamento" column in the FinanceiroLancamentoCaixa table. Then you would define the foreign key as ALTER TABLE FinanceiroLancamentoCaixa ADD CONSTRAINT FK_FinanceiroLancamentoCaixa_FinanceiroLancamento FOREIGN KEY (IdFinanceiroLancamento) REFERENCES FinanceiroLancamento(Id) ON DELETE CASCADE ON UPDATE CASCADE; Then, when you delete the FinanceiroLancamento record, the cascade deletes also the FinanceiroLancamentoCaixa record(s).

Categories : Sql Server

SQL Server query troubles, many-many relationship
You might need to add JOINS to get specific names, but this is the idea you're after: SELECT ItemID , MAX(CASE WHEN ShopID = 'Tesco' THEN CurrentStock ELSE 0 END)'Tesco Stock' , MAX(CASE WHEN ShopID = 'ASDA' THEN CurrentStock ELSE 0 END)'ASDA Stock' , MAX(CASE WHEN ShopID = 'Sainsbury' THEN CurrentStock ELSE 0 END)'SainsburyStock' FROM ShopStock GROUP BY ItemID Assuming one entry per item per shopID. If there are multiples then you would have to SUM() them, but the idea is the same.

Categories : SQL

client to server, socket in python many to one relationship
When your server's socket receives a connect attempt from a client, s.accept() returns the a socket object and ip,port information. What you need to do is save this new socket object in a list and poll this list. while True: c, addr = s.accept() clients.append(c) pressed = 0 Or better yet, use a dictionary of the ip:port tuple, and iterate over clients.iteritems() while True: c,addr = s.accept() clients[addr] = c A naive implementation might be: import socket clients={} server = socket.socket() host = socket.gethostname() port = 12349 s.bind((host, port)) s.listen(5) while True: c, addr = server.accept() clients[addr] = c pressed = 0 for eachsocket, eachaddrtuple in clients.iteritems(): print 'receiving data from %s'%eachaddrtuple data = c.recv(1024

Categories : Python

Create one to one relationship in sql server management studio
Why even do this ? You can directly add the foreign key to the branch in the Employee table. This removes an extra table and makes your schema simpler. The only case I see that would make your design ok is if each employee either always moves from branch to branch or is attached to multiple branches but both scenarios seem unlikely, especially since you say you want to model a 1-1 relationship and not an N-N relationship. Long story short, drop that BranchEmployees table.

Categories : Sql Server

Relationship among Application Server, Container, and Java EE new releases
Java EE is a collection of services. A particular version of Java EE specifies the version of each service container (e.g. Servlet). An application server hosts containers for different services (e.g. Servlet). A particular version of an app server typically comes bundled with certain versions of containers for different services, which typically match a Java EE version bundle. An application server can be patched to upgrade the container of a particular service. The procedure may be official or undocumented. Upgrading to a minor version is usually painless and supported. Upgrading to a major version is usually unsupported and can often lead to incompatibilities. Hope this helps.

Categories : Java

SQL Server Collapsing multiple columns into a string from a one to many relationship
There is not really going to be a method that has a golden lining, without testing. You can try a different method to see if it worth your while. I would probably start with the scalar udf method to see if it is worth while. Also make sure to Order you data, so results are consistent. You can find more detail here, http://jahaines.blogspot.in/2009/06/concatenating-column-values-part-1.html.. Here are some performance tests, http://jahaines.blogspot.in/2009/07/concatenating-column-values-part-2.html Edit: I wanted to add that this would probably best be done in the application tier, or even a CLR. The bottom line is this is not one of SQL Server's strengths and you will probably have to try a few methods to see what works best for your environment. If you are mostly concerned with leg

Categories : SQL

Saving a hasMany relationship containing array of IDs back to REST server using Ember-Data
If you're using a hasMany, then you want to be setting 'jobRole' with a collection of live JobRole objects, not with an array of IDs. // assume role1 and role2 are JobRole objects // obtained via store.find() (or something...) someUser.set('jobRole',[role1,role2]); Alternatively, if you want to set the property with a list of IDs, then you could just use a non-typed DS.attr and the array will be passed through as is. Lrt.User = DS.Model.extend({ jobRole: DS.attr() }); //then later someUser.set('jobRole',[1,42]);

Categories : Ember Js

How to fetch relationship with Ember Model if response doesn't include relationship?
You could use a computed property on posts model, and then write a custom adapter to get your posts out. App.Post = Ember.Model.extend({ comment_ids: attr(), comments: function() { return App.Comment.find(this.get("comment_ids"); }.property('comment_ids.[]') })

Categories : Ember Js

An attempt was made to remove a relationship between a (*) and a (*). However, one of the relationship's foreign keys (X) cannot be set to null
I assume that you are trying to "reset" a reference to its default value by assigning null to it, expecting L2S to adopt the database default. However, as for L2S, you're only nullifying a foreign key. It's not aware of any defaults in the database. So you have to change the reference by setting it to the default lookup object yourself. You could do that by adding a Reset() method to your classes, so you don't have to scatter this code all over the place.

Categories : Database

Finding Relationship between elements in a Tree structure, where no initial relationship
You can build a forest initially, and when you have a connection, join trees in the forest. If the hirerchy is indeed tree-like, by doing so you will end up with a tree - as expected. Regarding "no binary tree" - no problem, use a generalized tree. The implementation (in java-like language) would be something like: class Node<Key> { Node<Key> father; final Key root; final List<Node<Key>> sons = new LinkedList<Node<Key>>(); //constructor, methods and more fields if needed } One more thing - I'll add an extra dictionary (hash based/ tree based) to map from the employee/manager key to the node object representing this employee. If using the above data structure, the map will be something like Map<Key, Node<Key>>.

Categories : Algorithm

Django - Database design for many to many relationship involving an attribute of the relationship
You can definitely use an intermediary table pageQuestions for what you are looking to achieve. class Page: #attributes class Questions: #attributes pages = models.ManyToManyField(through = 'PageQuestions', ...) class PageQuestions: page = models.ForeignKey(Page) question = models.ForeignKey(Question) ordinal_number = models.IntegerField() class Meta: unique_together = (('page', 'question')) #optional For the sake of completeness, Added the blog you found on ManyToMany relationships

Categories : Django

How can I convert a one to many optional relationship to a one to one require relationship codefirst?
If it's truly going to be a one:one relationship, the easiest way to handle it is to store them in the same record: e.g. CREATE TABLE Tank ( tank_id Int IDENTITY NOT NULL, fish_id Int NULL ) (A tank with no fish would have a NULL fish_id value)

Categories : C#

UIModalTransitionStylePartialCurl not presenting viewController
You haven't initialized v2 . you should use this : UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Your_storyboard_name" bundle:nil]; ViewController2* v2 = [storyboard instantiateViewControllerWithIdentifier:@"Your_view_controller_identifier_from_storyboard"]; v2.modalTransitionStyle = UIModalTransitionStylePartialCurl; [self presentViewController:v2 animated:YES completion:NULL]; Do any additional checks to see if it's iPad or iPhone and fill the information as is required.

Categories : IOS

MFMailComposeViewController is not presenting itself correctly
The view controller that you present the mail view controller from needs to be full screen and at the front, if it isn't some parts of the view won't respond properly to touches and / or be properly visible (as you see).

Categories : Iphone

Presenting a Text Stream in iOS
I don't have time to write the code, as it's not simple. You will want to create a UITextView and append the string to the text view as you recieve new content. UITextView is a subclass of UIScrollView, so you can use all UIScrollView operations on it, including scrolling down to the bottom as new content is added. This is the best way to have good performance, as UIScrollView and UITextView are both tightly integrated into the graphics hardware on the device. If the text is really big (hundreds of megabytes) then you should also delete old text from the top of the text view as you add new text to the end. Just use the code you have now, but instead of NSLog(), append it to the UITextView.

Categories : IOS

Need help presenting a view controller
This would work as long as you have set the alert view delegate to the view controller you want to handle the presentation. I would suggest moving all of the functionality to the view controller though, i.e. present and handle the alert view from the same view controller, this can be triggered from an event from the button. I think this makes the code more readable and it doesn't really make sense for a button to know about alert views

Categories : Iphone

Presenting MFMailComposeViewController from NSObject
The object which presents the MFMailComposeViewController must be part of the view hierarchy, as the error message indicates. In other words, it must be a view controller that has a view currently visible. Your NSObject-derived class that has all your logic should have a delegate back to the UIViewController which it manages that it can call to tell it to display the MFMailComposeViewController. This pattern is integral to iOS development and is covered in the View Controller Programming guide. Here's an example: @protocol ACFeedback <NSObject> - (void)showFeedbackMailMessage; @end @interface ACDataThing : NSObject @property (nonatomic, weak) id<ACFeedback> feedbacker; @end @interface ACEmptyViewController : UIViewController<ACFeedback> ... When you instantiate ACDat

Categories : IOS

SQL Server : Combining Rows
The two lines differ by TERMS_CD, one is PNOW and the other is blank, since you're grouping on that field, the two lines are returned. If you take the MIN/MAX of that field, you will get the one line you desire. You have to decide which fields contribute to a distinct value in your situation.

Categories : SQL

Combining rows in SQL Server
For your example data SELECT C1, MAX(C2) AS C2, MAX(C3) AS C3 FROM YourTable GROUP BY C1 SQL Fiddle

Categories : Sql Server

SQL Server : Columns to Rows
You can use the UNPIVOT function to convert the columns into rows: select id, entityId, indicatorname, indicatorvalue from yourtable unpivot ( indicatorvalue for indicatorname in (Indicator1, Indicator2, Indicator3) ) unpiv; Note, the datatypes of the columns you are unpivoting must be the same so you might have to convert the datatypes prior to applying the unpivot. You could also use CROSS APPLY with UNION ALL to convert the columns: select id, entityid, indicatorname, indicatorvalue from yourtable cross apply ( select 'Indicator1', Indicator1 union all select 'Indicator2', Indicator2 union all select 'Indicator3', Indicator3 union all select 'Indicator4', Indicator4 ) c (indicatorname, indicatorvalue); Depending on your version of SQL Server you could even u

Categories : SQL

SQL Server : why are there no rows found?
Possible, the first character in f_firm_name - is a space. So try this one - SELECT TOP 20 f_firm_name = f.name FROM dbo.Firm f WHERE f.id_city = '73041' AND LTRIM(f.name) LIKE 'ВЕРТЕКС ЗАО%' --<-- COLLATE SQL_Latin1_General_Cp1251_CI_AS ORDER BY f.name

Categories : Sql Server

SQL Server : rows into columns
My suggestion when you are working with dynamic SQL is to always write the query hard-coded first, so you can get the logic correct, then convert it to dynamic SQL. Since you are attempting to pivot 3 columns of data I would first unpivot the type_ds, expdt and comdt` columns, then apply the PIVOT function. The hard-coded version of the query will be: SELECT * FROM ( select pro_id, type_ds = case when col ='type_ds' then type_ds else type_ds+col end, value from ( SELECT A.Pro_Id, c.Type_DS, convert(varchar(10), b.ExpDt, 120) ExpDt, convert(varchar(10), b.ComDt, 120) ComDt FROM dbo.Project A left join [dbo].[Prj_App] B on A.Pro_id = B.Pro_Id right outer join dbo.

Categories : Sql Server

How to compare two rows in SQL Server
SQL Server does not allow you to use aliases in the WHERE clause. You'll have to have something like this: SELECT *, Customers - C_COUNT "Difference" FROM ( SELECT A.customers AS CUSTOMERS, (SELECT COUNT(ID) FROM Partners_customers B WHERE A.ID = B.PIID) AS C_COUNT FROM Partners A ) t WHERE CUSTOMERS <> [C_COUNT] Or, better yet, eliminating an inline count: select A.customers, count(b.id) FROM Partners A LEFT JOIN Partners_customers B ON A.ID = B.PIID Group By A.ID having a.customers <> count(b.id)

Categories : SQL

Get rows with more then a word with SQL Server
One word select * from tablename where fieldname not like '% %' multiple words select * from tablename where fieldname like '% %' EDIT if leading / trailing spaces could be an issue, you can use something like select * from tablename where ltrim(rtrim(fieldname)) like '% %'

Categories : SQL

Best practise in creating an uiview and presenting them in iOs
One of my first iOS applications had a tab bar and views that the user could switch between. Originally it was done by hiding and showing the right views depending on what the user pressed on the tab bar. This ended up being a complex disaster. I then rewrote the app so that each tab bar view had its own UIViewController with its own set of views. That turned out to be so much easier to manage. (I also changed from using Interface Builder to straight code for creating the views, but that's beside the point and you can continue to use IB if you want.)

Categories : IOS

View Controller not presenting from App Delegate
Actually this is the correct way of loading a ViewController from AppDelegate.. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; DefaultViewController *viewController = [[DefaultViewController alloc] initWithNibName:@"DefaultViewController" bundle:nil]; self.window.rootViewController = viewController; [self.window makeKeyAndVisible];

Categories : Iphone

Popover presenting underneath modal
After a night's sleep I instantly discovered the problem: destination.view.layer.zPosition = 1000; Because I am doing some 3D affine transforms in the animation, I needed to raise the zPosition of the destination view's layer so that it doesn't clip the source view's layer when rotating. I was forgetting to change the zPosition back to 0 when it completes.

Categories : IOS

Getting Tor Control data through Stem and presenting on the web with web.py
Your usage of stem looks right though you might want to look into BW events if you expand this to do multiple datapoints. As for web.py, the examples on their site return a view.render.base instance, maybe that's the missing bit?

Categories : Python

Scraping IDs from three different divs and presenting them as an array?
Try following: children = @data.css('#sub_div') children_array = children.css('.subl .node').map { |node| node.text.to_i } OR children = @data.css('#sub_div') children_array = children.css('.subl .node').map(&:text).map(&:to_i)

Categories : Ruby

dismissViewControllerAnimated issue: presenting controller is gone
The documentation says about dismissViewControllerAnimated:completion: The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, it automatically forwards the message to the presenting view controller. If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, whic

Categories : IOS



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