Search Results

Search found 4815 results on 193 pages for 'parameterized queries'.

Page 20/193 | < Previous Page | 16 17 18 19 20 21 22 23 24 25 26 27  | Next Page >

  • SQLAlchemy & Complex Queries

    - by user356594
    I have to implement ACL for an existing application. So I added the a user, group and groupmembers table to the database. I defined a ManyToMany relationship between user and group via the association table groupmembers. In order to protect some ressources of the app (i..e item) I added a additional association table auth_items which should be used as an association table for the ManyToMany relationship between groups/users and the specific item. item has following columns: user_id -- user table group_id -- group table item_id -- item table at least on of user_id and group_id columns are set. So it's possible to define access for a group or for a user to a specific item. I have used the AssociationProxy to define the relationship between users/groups and items. I now want to display all items which the user has access to and I have a really hard time doing that. Following criteria are used: All items which are owned by the user should be shown (item.owner_id = user.id) All public items should be shown (item.access = public) All items which the user has access to should be shown (auth_item.user_id = user.id) All items which the group of the user has access to should be shown. The first two criteria are quite straightforward, but I have a hard time doing the 3rd one. Here is my approach: clause = and_(item.access == 'public') if user is not None: clause = or_(clause,item.owner == user,item.users.contains(user),item.groups.contains(group for group in user.groups)) The third criteria produces an error. item.groups.contains(group for group in user.groups) I am actually not sure if this is a good approach at all. What is the best approach when filtering manytomany relationships? How I can filter a manytomany relationship based on another list/relationship? Btw I am using the latest sqlalchemy (6.0) and elixir version Thanks for any insights.

    Read the article

  • PHP: Join two separate mysql queries into the same json data object

    - by Dan
    I'm trying to mesh the below mysql query results into a single json object, but not quite sure how to do it properly. //return data $sql_result = mysql_query($sql,$connection) or die ("Fail."); $arr = array(); while($obj = mysql_fetch_object($sql_result)) { $arr[] = $obj; } echo json_encode($arr); //return json //plus the selected options $sql_result2 = mysql_query($sql2,$connection) or die ("Fail."); $arr2 = array(); while($obj2 = mysql_fetch_object($sql_result2)) { $arr2[] = $obj2; } echo json_encode($arr2); //return json Here's the current result: [{"po_number":"test","start_date":"1261116000","end_date":"1262239200","description":"test","taa_required":"0","account_overdue":"1","jobs_id":null,"job_number":null,"companies_id":"4","companies_name":"Primacore Inc."}][{"types_id":"37"},{"types_id":"4"}] Notice how the last section [{"types_id":"37"},{"types_id":"4"}] is placed into a separate chunk under root. I'm wanting it to be nested inside the first branch under a name like, "types". I think my question has more to do with Php array manipulation, but I'm not the best with that. Thank you for any guidance.

    Read the article

  • SQL Select queries

    - by sds
    Which is better and what is the difference? SELECT * FROM TABLE_A A WHERE A.ID IN (SELECT B.ID FROM TABLE_B B) or SELECT * FROM TABLE_A A, TABLE_B B WHERE A.ID = B.ID

    Read the article

  • What's the difference between these LINQ queries ?

    - by SnAzBaZ
    I use LINQ-SQL as my DAL, I then have a project called DB which acts as my BLL. Various applications then access the BLL to read / write data from the SQL Database. I have these methods in my BLL for one particular table: public IEnumerable<SystemSalesTaxList> Get_SystemSalesTaxList() { return from s in db.SystemSalesTaxLists select s; } public SystemSalesTaxList Get_SystemSalesTaxList(string strSalesTaxID) { return Get_SystemSalesTaxList().Where(s => s.SalesTaxID == strSalesTaxID).FirstOrDefault(); } public SystemSalesTaxList Get_SystemSalesTaxListByZipCode(string strZipCode) { return Get_SystemSalesTaxList().Where(s => s.ZipCode == strZipCode).FirstOrDefault(); } All pretty straight forward I thought. Get_SystemSalesTaxListByZipCode is always returning a null value though, even when it has a ZIP Code that exists in that table. If I write the method like this, it returns the row I want: public SystemSalesTaxList Get_SystemSalesTaxListByZipCode(string strZipCode) { var salesTax = from s in db.SystemSalesTaxLists where s.ZipCode == strZipCode select s; return salesTax.FirstOrDefault(); } Why does the other method not return the same, as the query should be identical ? Note that, the overloaded Get_SystemSalesTaxList(string strSalesTaxID) returns a record just fine when I give it a valid SalesTaxID. Is there a more efficient way to write these "helper" type classes ? Thanks!

    Read the article

  • Rails advanced queries with join and sum calculation

    - by Dustin Brewer
    I have two models: companies and expenses. Companies have many expenses and expenses belong to companies. My expense model has an 'amount' column. I was wondering if there is a way to perform a find based on a date range and the amount column of the expenses. Something like top 3 companies by total expense amounts over a 7 day period. I've tried for the better part of the day to get this to work, I've attempted joins, chaining named scopes, raw sql, etc. and I'm not having any luck. Thanks for the help.

    Read the article

  • .NET | Persist multiple objects in minimum number of queries

    - by VarunGupta
    I have a list of objects which needs to be persisted in a SQL Server database table, where each object gets persisted as single record. i.e. List of objects result in insertion of multiple records. Trivial way of saving the objects is to loop over the list and fire a query/stored procedure/etc. for saving that record. But this results in multiple database interactions. Is there a way to persist the list of objects in lesser number of database interactions?

    Read the article

  • exploratory SPARQL queries?

    - by significance
    whenever i start using sql i tend to throw a couple of exploratory statements at the database in order to understand what is avaliable, and what form the data takes. eg. show tables describe table select * from table could anyone help me understand the way to complete a similar exploration of an rdf datastore using a SPARQL endpoint? Thanks :)

    Read the article

  • Linq Queries converting to lambda expressions ?

    - by Freshblood
    Hello from item in range where item % 2 ==0 select i ; is converting to lamda expressions as below range.where(item % 2 ==0).select(x=>x). I feel that first way of linq is translating next one and if it is ,so is there any optimization like this range.where(item & 2 == 0) instead of other one ?

    Read the article

  • Storing SQL queries in Table in sql server

    - by Rohit
    We have multiple jobs in our system.These jobs are listed in a grid. We have 3 different user types (usertypeid 1,2,3). For each user listing is different and he can filter listing by selecting view from a dropdown. ViewName in the below table is the view which needs to be displayed. To achieve this functionality, a fellow developer has created the following table structure and stored sql fragments in SQLExpression in the below table. According to me the query should not be stored in database. What are the pros and cons of this approach and what are the available alternatives? JobListingViewID ViewName SQLExpression UserTypeID 3 All Jobs 1 = 1 3 4 Error Jobs JobStatusID IN ( 2 ) 1 5 Error Jobs JobStatusID IN ( 2 ) 2 6 Error Jobs JobStatusID IN ( 2 ) 3 7 Speech JobStatusID IN ( 1, 3, 8 ) 1

    Read the article

  • Interpret a rule applying multiple xpath queries on multiple XML documents

    - by Damien
    Hi, I need to build a component which would take a few XML documents in input and check the following kind of rules: XML1:/bookstore/book[price>35.00] != null and (XML2:/city/name = 'Montreal' or XML3://customer[@language] contains 'en') Basically my component should be able to: substitute the XML tokens with the corresponding XML document(before colon) apply xpath query on this XML document check the xpath output against expected result ("=", "!=", "contains") follow the basic syntax ("and", "or" and parentheses) tell if the rule is true or false Do you know any library which could help me? maybe JavaCC? Thanks

    Read the article

  • DDEX Firebird editing queries duplicates columns in Visual Studio 2008

    - by A Bothe
    Hello everybody! I don't know if some of you also has experienced it but when I edit a query in Visual Studio (it uses DDEX 2.0.5 for accessing the Firebird 2.5 database), it duplicates some of the columns. What's really interesting is the fact that only System.Boolean columns are duplicated: Originally, there was only ,for instance, a 'PRO_DELETED' field... Now I wanted to sort my results by this field - I had to change the select statement in the so-called QueryBuilder by adding "ORDER BY PRO_DELETED" ...After clicking OK it somehow created a new column (!?) called 'PRO_DELETED1' My question is: Why does DDEX add such a new row to the column view and why can't I access the original PRO_DELETED field anymore? Thanks in advance!

    Read the article

  • Redirecting all page queries to the homepage in Rails

    - by Dean Putney
    I've got a simple Rails application running as a splash page for a website that's going through a transition to a new server. Since this is an established website, I'm seeing user requests hitting pages that don't exist in the Rails application. How can I redirect all unknown requests to the homepage instead of throwing a routing error?

    Read the article

  • Advantage Database Server: in-memory queries.

    - by ie
    As far as I know, ADS v.10 tries to keep result of query in memory until it is a quite huge. The same should be true for the __output table and for temporary tables. When the result becoming large, swapping stated. The question is what memory limit is set for a query, a worker, whatever? Could this limit be configured? Thanks.

    Read the article

  • Data historian queries

    - by Scott Dennis
    Hi, I have a table that contains data for electric motors the format is: DATE(DateTime) | TagName(VarChar(50) | Val(Float) | 2009-11-03 17:44:13.000 | Motor_1 | 123.45 2009-11-04 17:44:13.000 | Motor_1 | 124.45 2009-11-05 17:44:13.000 | Motor_1 | 125.45 2009-11-03 17:44:13.000 | Motor_2 | 223.45 2009-11-04 17:44:13.000 | Motor_2 | 224.45 Data for each motor is inserted daily, so there would be 31 Motor_1s and 31 Motor_2s etc. We do this so we can trend it on our control system displays. I am using views to extract last months max val and last months min val. Same for this months data. Then I join the two and calculate the difference to get the actual run hours for that month. The "Val" is a nonresetable Accumulation from a PLC(Controller). This is my query for Last months Max Value: SELECT TagName, Val AS Hours FROM dbo.All_Data_From_Last_Mon AS cur WHERE (NOT EXISTS (SELECT TagName, Val FROM dbo.All_Data_From_Last_Mon AS high WHERE (TagName = cur.TagName) AND (Val > cur.Val))) This is my query for Last months Max Value: SELECT TagName, Val AS Hours FROM dbo.All_Data_From_Last_Mon AS cur WHERE (NOT EXISTS (SELECT TagName, Val FROM dbo.All_Data_From_Last_Mon AS high WHERE (TagName = cur.TagName) AND (Val < cur.Val))) This is the query that calculates the difference and runs a bit slow: SELECT dbo.Motors_Last_Mon_Max.TagName, STR(dbo.Motors_Last_Mon_Max.Hours - dbo.Motors_Last_Mon_Min.Hours, 12, 2) AS Hours FROM dbo.Motors_Last_Mon_Min RIGHT OUTER JOIN dbo.Motors_Last_Mon_Max ON dbo.Motors_Last_Mon_Min.TagName = dbo.Motors_Last_Mon_Max.TagName I know there is a better way. Ultimately I just need last months total and this months total. Any help would be appreciated. Thanks in advance

    Read the article

  • Linq, should I join those two queries together?

    - by 5YrsLaterDBA
    I have a Logins table which records when user is login, logout or loginFailed and its timestamp. Now I want to get the list of loginFailed after last login and the loginFailed happened within 24 hrs. What I am doing now is get the last login timestamp first. then use second query to get the final list. do you think I should join those two queris together? why not? why yes? var lastLoginTime = (from inRecord in db.Logins where inRecord.Users.UserId == userId && inRecord.Action == "I" orderby inRecord.Timestamp descending select inRecord.Timestamp).Take(1); if (lastLoginTime.Count() == 1) { DateTime lastInTime = (DateTime)lastLoginTime.First(); DateTime since = DateTime.Now.AddHours(-24); String actionStr = "F"; var records = from record in db.Logins where record.Users.UserId == userId && record.Timestamp >= since && record.Action == actionStr && record.Timestamp > lastInTime orderby record.Timestamp select record; }

    Read the article

  • nested join linq-to-sql queries

    - by ile
    var result = ( from contact in db.Contacts where contact.ContactID == id join referContactID in db.ContactRefferedBies on contact.ContactID equals referContactID.ContactID join referContactName in db.Contacts on contact.ContactID equals referContactID.ContactID orderby contact.ContactID descending select new ContactReferredByView { ContactReferredByID = referContactID.ContactReferredByID, ContactReferredByName = referContactName.FirstName + " " + referContactName.LastName }).Single(); Problem is in this line: join referContactName in db.Contacts on contact.ContactID equals referContactID.ContactID where referContactID.ContactID is called from the above join line. How to nest these two joins? Thanks in advance! Ile

    Read the article

  • Java: Making concurrent MySQL queries from multiple clients synchronised

    - by Misha Gale
    I work at a gaming cybercafe, and we've got a system here (smartlaunch) which keeps track of game licenses. I've written a program which interfaces with this system (actually, with it's backend MySQL database). The program is meant to be run on a client PC and (1) query the database to select an unused license from the pool available, then (2) mark this license as in use by the client PC. The problem is, I've got a concurrency bug. The program is meant to be launched simultaneously on multiple machines, and when this happens, some machines often try and acquire the same license. I think that this is because steps (1) and (2) are not synchronised, i.e. one program determines that license #5 is available and selects it, but before it can mark #5 as in use another copy of the program on another PC tries to grab that same license. I've tried to solve this problem by using transactions and table locking, but it doesn't seem to make any difference - Am I doing this right? Here follows the code in question: public LicenseKey Acquire() throws SmartLaunchException, SQLException { Connection conn = SmartLaunchDB.getConnection(); int PCID = SmartLaunchDB.getCurrentPCID(); conn.createStatement().execute("LOCK TABLE `licensekeys` WRITE"); String sql = "SELECT * FROM `licensekeys` WHERE `InUseByPC` = 0 AND LicenseSetupID = ? ORDER BY `ID` DESC LIMIT 1"; PreparedStatement statement = conn.prepareStatement(sql); statement.setInt(1, this.id); ResultSet results = statement.executeQuery(); if (results.next()) { int licenseID = results.getInt("ID"); sql = "UPDATE `licensekeys` SET `InUseByPC` = ? WHERE `ID` = ?"; statement = conn.prepareStatement(sql); statement.setInt(1, PCID); statement.setInt(2, licenseID); statement.executeUpdate(); statement.close(); conn.commit(); conn.createStatement().execute("UNLOCK TABLES"); return new LicenseKey(results.getInt("ID"), this, results.getString("LicenseKey"), results.getInt("LicenseKeyType")); } else { throw new SmartLaunchException("All licenses of type " + this.name + "are in use"); } }

    Read the article

  • Which of these queries is preferable?

    - by bread
    I've written the same query as a subquery and a self-join. Is there any obvious argument for one over the other here? SUBQUERY: SELECT prod_id, prod_name FROM products WHERE vend_id = (SELECT vend_id FROM products WHERE prod_id = ‘DTNTR’); SELF-JOIN: SELECT p1.prod_id, p1.prod_name FROM products p1, products p2 WHERE p1.vend_id = p2.vend_id AND p2.prod_id = ‘DTNTR’;

    Read the article

  • passing multiple queries to view with codeigniter

    - by LvS
    I am trying to build a forum with Codeigniter. So far i have the forums themselves displayed and the threads displayed, based on the creating dynamic news tutorial. But that is 2 different pages, i need to obviously display them into one page, like this: Forum 1 - thread 1 - thread 2 - thread 3 Forum 2 - thread 1 - thread 2 etc. And then the next step is obviously to display all the posts in a thread. Most likely with some pagination going on. But that is for later. For now i have the forum controller (slimmed version): <?php class Forum extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('forum_model'); $this->lang->load('forum'); $this->lang->load('dutch'); } public function index() { $data['forums'] = $this->forum_model->get_forums(); $data['title'] = $this->lang->line('title'); $data['view'] = $this->lang->line('view'); $this->load->view('templates/header', $data); $this->load->view('forum/index', $data); $this->load->view('templates/footer'); } public function view($slug) { $data['forum_item'] = $this->forum_model->get_forums($slug); if (empty($data['forum_item'])) { show_404(); } $data['title'] = $data['forum_item']['title']; $this->load->view('templates/header', $data); $this->load->view('forum/view', $data); $this->load->view('templates/footer'); } } ?> And the forum_model (also slimmed down) <?php class Forum_model extends CI_Model { public function __construct() { $this->load->database(); } public function get_forums($slug = FALSE) { if ($slug === FALSE) { $query= $this->db->get('forum'); return $query->result_array(); } $query = $this->db->get_where('forum', array('slug' => $slug)); return $query->row_array(); } public function get_threads($forumid, $limit, $offset) { $query = $this->db->get_where('thread', array('forumid', $forumid), $limit, $offset); return $query->result_array(); } } ?> And the view file <?php foreach ($forums as $forum_item): ?> <h2><?=$forum_item['title']?></h2> <div id="main"> <?=$forum_item['description']?> </div> <p><a href="forum/<?php echo $forum_item['slug'] ?>"><?=$view?></a></p> <?php endforeach ?> Now that last one, i would like to have something like this: <?php foreach ($forums as $forum_item): ?> <h2><?=$forum_item['title']?></h2> <div id="main"> <?=$forum_item['description']?> </div> <?php foreach ($threads as $thread_item): ?> <h2><?php echo $thread_item['title'] ?></h2> <p><a href="thread/<?php echo $thread_item['slug'] ?>"><?=$view?></a></p> <?php endforeach ?> <?php endforeach ?> But the question is, how do i get the model to return like a double query to the view, so that it contains both the forums and the threads within each forum. I tried to make a foreach loop in the get_forum function, but when i do this: public function get_forums($slug = FALSE) { if ($slug === FALSE) { $query= $this->db->get('forum'); foreach ($query->row_array() as $forum_item) { $thread_query=$this->get_threads($forum_item->forumid, 50, 0); } return $query->result_array(); } $query = $this->db->get_where('forum', array('slug' => $slug)); return $query->row_array(); } i get the error A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: models/forum_model.php Line Number: 16 I hope anyone has some good tips, thanks! Lenny *EDIT*** Thanks for the feedback. I have been puzzling and this seems to work now :) $query= $this->db->get('forum'); foreach ($query->result() as $forum_item) { $forum[$forum_item->forumid]['title']=$forum_item->title; $thread_query=$this->db->get_where('thread', array('forumid' => $forum_item->forumid), 20, 0); foreach ($thread_query->result() as $thread_item) { $forum[$forum_item->forumid]['thread'][]=$thread_item->title; } } return $forum; } What is now next, is how to display this multidimensional array in the view, with foreach statements.... Any suggestions ? Thanks

    Read the article

  • Exposing entities via a nHibernate implementation RIA Services with querystring queries

    - by illdev
    I once read a blog post and cannot find it anymore. drat! It was about a guy who setup a wcf service (I guess RIA, but could have been something else) exposing the model via IQueryable to the querystring. Sou you could say http://host/articles/123/ratings and you'd get a list (soap or json) of serialized Rating entities (the properties which had some attribute attached) which pertained to an article with id 123. All this with nHibernate / nh linq in the back and in surprisingly few lines of code. Anyone knows what I am talking about? Experiences, suggestions?

    Read the article

  • Why does mobile first responsive design tend to not use max-width queries alongside the min-width queries?

    - by Sam
    First off, I understand the basic principles behind mobile first responsive web design, and totally agree with them. But one thing I don't understand: In my experience, not all styles for small screens can be used for the larger version of a website. For example, usually smaller versions tend to have larger clickable areas, hamburger navigation, etc. So I sometimes have to override these specific styles, aside from just progressively enhancing the base styles. So I was wondering: why is max-width rarely mentioned (or used) in the context of mobile-first responsive web design? Because it looks like it could be used to isolate styles for smaller screens that are not useful for larger screens, and would thus prevent unnecessary duplication of code. A quote which mentions min-width as typically mobile-first, but not max-width: Mobile first, from a coding perspective, means that your base style is typically a single-column, fully-fluid layout. You use @media (min-width: whatever) to add a grid-based layout on top of that. from: http://gomakethings.com/mobile-first-and-internet-explorer/ EDIT: So to be more specific: I was wondering if there is a reason to exclude max-width from a mobile-first responsive design (as it seems like it can be useful for writing your css as DRY as possible, as some styles for small screens will not be used for bigger screens).

    Read the article

  • How to prompt user input parameters for SQL Queries in Access 2010

    - by user1848907
    SELECT Transactions.TransactionNumber FROM Transactions WHERE (((Transactions.Date)>=#11/23/12#)) AND (((Transactions.Date)<=#11/23/12#)); The above code returns all the transaction that happened between the specified dates. But I want those dates to be defined by the user every time the query is executed. I tried using the [] operators to have the user define the criteria in the WHERE, something like this: WHERE (((Transactions.Date)>=[Input a Date])) AND (((Transactions.Date)<=[Input a Date])); But microsoft Access throws a Syntax error message. The same happens when I include the # (date operators) like this WHERE (((Transactions.Date)>=#[Input a Date]#)) AND (((Transactions.Date)<=#[Input a Date]#)); Is there anopther way to manage dates that I'm not aware of or is asking a user for dates in a query out of the question

    Read the article

< Previous Page | 16 17 18 19 20 21 22 23 24 25 26 27  | Next Page >