Search Results

Search found 8267 results on 331 pages for 'insert'.

Page 13/331 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • Transaction Isolation on select, insert, delete

    - by Bradford
    What could possibly go wrong with the following transaction if executed by concurrent users in the default isolation level of READ COMMITTED? BEGIN TRANSACTION SELECT * FROM t WHERE pid = 10 and r between 40 and 60 -- ... this returns tid = 1, 3, 5 -- ... process returned data ... DELETE FROM t WHERE tid in (1, 3, 5) INSERT INTO t (tid, pid, r) VALUES (77, 10, 35) INSERT INTO t (tid, pid, r) VALUES (78, 10, 37) INSERT INTO t (tid, pid, r) VALUES (79, 11, 39) COMMIT

    Read the article

  • Are there any nasty side affects if i lock the HttpContext.Current.Cache.Insert method

    - by Ekk
    Apart from blocking other threads reading from the cache what other problems should I be thinking about when locking the cache insert method for a public facing website. The actual data retrieval and insert into the cache should take no more than 1 second, which we can live with. More importantly i don't want multiple thread potentially all hitting the Insert method at the same time. The sample code looks something like: public static readonly object _syncRoot = new object(); if (HttpContext.Current.Cache["key"] == null) { lock (_syncRoot) { HttpContext.Current.Cache.Insert("key", "DATA", null, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null); } } Response.Write(HttpContext.Current.Cache["key"]);

    Read the article

  • I'm looking for a constraint to prevent the insert of an empty string in MySQL

    - by Marga Keuvelaar
    Ok, in this question I learned how to prevent the insert of a NULL value. But, unfortunately, an empty string is being inserted anyway. Apart from preventing this on the PHP side, I'd like to use something like a database constraint to prevent this. Of course a check on the application side is necessary, but I'd like it to be on both sides. I am taught that whatever application is talking to your database, it should not be able to insert basically wrong data in it. So... CREATE TABLE IF NOT EXISTS tblFoo ( foo_id int(11) NOT NULL AUTO_INCREMENT, foo_test varchar(50) NOT NULL, PRIMARY KEY (foo_id) ); Would still allow me to do this insert: INSERT INTO tblFoo (foo_test) VALUES (''); Which I would like to prevent.

    Read the article

  • How to write a good PHP database insert using an associative array

    - by Tom
    In PHP, I want to insert into a database using data contained in a associative array of field/value pairs. Example: $_fields = array('field1'=>'value1','field2'=>'value2','field3'=>'value3'); The resulting SQL insert should look as follows: INSERT INTO table (field1,field2,field3) VALUES ('value1','value2','value3'); I have come up with the following PHP one-liner: mysql_query("INSERT INTO table (".implode(',',array_keys($_fields)).") VALUES (".implode(',',array_values($_fields)).")"); It separates the keys and values of the the associative array and implodes to generate a comma-separated string . The problem is that it does not escape or quote the values that were inserted into the database. To illustrate the danger, Imagine if $_fields contained the following: $_fields = array('field1'=>"naustyvalue); drop table members; --"); The following SQL would be generated: INSERT INTO table (field1) VALUES (naustyvalue); drop table members; --; Luckily, multiple queries are not supported, nevertheless quoting and escaping are essential to prevent SQL injection vulnerabilities. How do you write your PHP Mysql Inserts? Note: PDO or mysqli prepared queries aren't currently an option for me because the codebase already uses mysql extensively - a change is planned but it'd take alot of resources to convert?

    Read the article

  • mysql insert multiple rows, return rows that failed

    - by Glenn
    When I try to insert (lets say) 30 rows in my table. For example INSERT INTO customers(cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country) VALUES( 'Pep E. LaPew', '100 Main Street', 'Los Angeles', 'CA', '90046', 'USA' ), ( 'M. Martian', '42 Galaxy Way', 'New York', 'NY', '11213', 'USA' ), ... ; And cust_name has to be unique. How can I then identify the records that failed to insert because their cust_name already exists? Is it possible to return them?

    Read the article

  • MySQL Inserting into locked aliased table

    - by Whitey
    I am trying to insert data into a InnoDB MySQL table which is locked using an alias and I cannot for the life of me get it to work! The following works: LOCK TABLES Problems p1 WRITE, Problems p2 WRITE, Server READ; SELECT * FROM Problems p1; UNLOCK TABLES; But try and do an insert and it doesn't work (it claims there is a syntax error round the 'p1' in my INSERT): LOCK TABLES Problems p1 WRITE, Problems p2 WRITE, Server READ; INSERT INTO Problems p1 (SomeCol) VALUES(43534); UNLOCK TABLES; Help please!

    Read the article

  • insert into several inheritance tables with OUTPUT - sql servr 2005

    - by csetzkorn
    Hi, I have a bunch of items – for simplicity reasons – a flat table with unique names seeded via bulk insert: create table #items ( ItemName NVARCHAR(255) ) The database has this structure: create table Statements ( Id INT IDENTITY NOT NULL, Version INT not null, FurtherDetails varchar(max) null, ProposalDateTime DATETIME null, UpdateDateTime DATETIME null, ProposerFk INT null, UpdaterFk INT null, primary key (Id) ) create table Item ( StatementFk INT not null, ItemName NVARCHAR(255) null, primary key (StatementFk) ) Here Item is a child of Statement (inheritance). I would like to insert items in #items using a set based approach (avoiding triggers and loops). Can this be achieved with OUTPUT in my scenario. A ‘loop based’ approach is just too slow where I use something like this: insert into Statements (Version, FurtherDetails, ProposalDateTime, UpdateDateTime, ProposerFk, UpdaterFk) VALUES (1, null, getdate(), getdate(), @user_id, @user_id) etc. This is a start for the OUTPUT based approach – but I am not sure whether this would work in my case as ItemName is only inserted into Item: insert into Statements ( Version, FurtherDetails, ProposalDateTime, UpdateDateTime, ProposerFk, UpdaterFk ) output inserted.Id ... ??? Thanks. Best wishes, Christian

    Read the article

  • Getting row right after insert returns no result

    - by Peekyou
    I am running unit tests and when I try to insert data in the database and getting it right after, I don't get anything (I have tried with DataAdapter and DataReader). However when I put a 3 seconds sleep (even with 1 second it doesn't work...) between the insert and the select I get the result. In SQL Server Profiler I can see the execution, the insert is well done and is completed about 10 miliseconds before the select begins. I can't find out where this comes

    Read the article

  • INSERT INTO statement that copies rows and auto-increments non-identity key ID column

    - by AmoebaMan17
    Given a table that has three columns ID (Primary Key, not-autoincrementing) GroupID SomeValue I am trying to write a single SQL INSERT INTO statement that will make a copy of every row that has one GroupID into a new GroupID. Example beginning table: ID | GroupID | SomeValue ------------------------ 1 | 1 | a 2 | 1 | b Goal after I run a simple INSERT INTO statement: ID | GroupID | SomeValue ------------------------ 1 | 1 | a 2 | 1 | b 3 | 2 | a 4 | 2 | b I thought I could do something like: INSERT INTO MyTable ( [ID] ,[GroupID] ,[SomeValue] ) ( SELECT (SELECT MAX(ID) + 1 FROM MyTable) ,@NewGroupID ,[SomeValue] FROM MyTable WHERE ID = @OriginalGroupID ) This causes a PrimaryKey violation since it will end up reusing the same Max(ID)+1 value multiple times as it seems. Is my only recourse to a bunch of INSERT statements in a T-SQL WHILE statement that has an incrementing Counter value? I also don't have the option of turning the ID into an auto-incrementing Identity column since that would breaking code I don't have source for.

    Read the article

  • BULK INSERT from one table to another all on the server

    - by steve_d
    I have to copy a bunch of data from one database table into another. I can't use SELECT ... INTO because one of the columns is an identity column. Also, I have some changes to make to the schema. I was able to use the export data wizard to create an SSIS package, which I then edited in Visual Studio 2005 to make the changes desired and whatnot. It's certainly faster than an INSERT INTO, but it seems silly to me to download the data to a different computer just to upload it back again. (Assuming that I am correct that that's what the SSIS package is doing). Is there an equivalent to BULK INSERT that runs directly on the server, allows keeping identity values, and pulls data from a table? (as far as I can tell, BULK INSERT can only pull data from a file) Edit: I do know about IDENTITY_INSERT, but because there is a fair amount of data involved, INSERT INTO ... SELECT is kinda of slow. SSIS/BULK INSERT dumps the data into the table without regards to indexes and logging and whatnot, so it's faster. (Of course creating the clustered index on the table once it's populated is not fast, but it's still faster than the INSERT INTO...SELECT that I tried in my first attempt) Edit 2: The schema changes include (but are not limited to) the following: 1. Splitting one table into two new tables. In the future each will have its own IDENTITY column, but for the migration I think it will be simplest to use the identity from the original table as the identity for the both new tables. Once the migration is over one of the tables will have a one-to-many relationship to the other. 2. Moving columns from one table to another. 3. Deleting some cross reference tables that only cross referenced 1-to-1. Instead the reference will be a foreign key in one of the two tables. 4. Some new columns will be created with default values. 5. Some tables aren’t changing at all, but I have to copy them over due to the "put it all in a new DB" request.

    Read the article

  • How to track auto-generated id's in select-insert statement

    - by k rey
    I have two tables detail and head. The detail table will be written first. Later, the head table will be written. The head is a summary of the detail table. I would like to keep a reference from the detail to the head table. I have a solution but it is not elegant and requires duplicating the joins and filters that were used during summation. I am looking for a better solution. The below is an example of what I currently have. In this example, I have simplified the table structure. In the real world, the summation is very complex. -- Preparation create table #detail ( detail_id int identity(1,1) , code char(4) , amount money , head_id int null ); create table #head ( head_id int identity(1,1) , code char(4) , subtotal money ); insert into #detail ( code, amount ) values ( 'A', 5 ); insert into #detail ( code, amount ) values ( 'A', 5 ); insert into #detail ( code, amount ) values ( 'B', 2 ); insert into #detail ( code, amount ) values ( 'B', 2 ); -- I would like to somehow simplify the following two queries insert into #head ( code, subtotal ) select code, sum(amount) from #detail group by code update #detail set head_id = h.head_id from #detail d inner join #head h on d.code = h.code -- This is the desired end result select * from #detail Desired end result of detail table: detail_id code amount head_id 1 A 5.00 1 2 A 5.00 1 3 B 2.00 2 4 B 2.00 2

    Read the article

  • how to escape a string before insert or update in Ruby

    - by ywenbo
    Hi guy, In ruby ActiveRecord doesn't provide dynamic binding for update and insert sqls, of course i can use raw sql, but that need maintain connection, so i want to know if there is simpler way to escape update or insert sql before executing like code below: ActiveRecord::Base.connection.insert(sql) i think i can write code by gsub, but i know if there has been a ready method to do it. thank you very much, and Merry Christmas for you all.

    Read the article

  • SQL INSERT performance omitting field names?

    - by Marco Demaio
    Does anyone knows if removing the field names from an INSERT query results in some performance improvements? I mean is this: INSERT INTO table1 VALUES (value1, value2, ...) faster for DB to be accomplished rather than doing this: INSERT INTO table1 (field1, field2, ...) VALUES (value1, value2, ...) ? I know it might be probably a meaningless performance difference, but just to know.

    Read the article

  • Why does /**[newline] not always insert the Javadoc template including @param and @return in Eclipse

    - by Bas van den Broek
    I'm documenting code in Eclipse and have been using the /** followed by Enter alot to insert the Javadoc template. However this does not always work for some reason, it will create the template for writing comments but it won't automatically insert the @param and @return text. If I copy the exact same method to another class it will insert the full template. It would be a big help if anyone could tell me why it won't do this in some situations.

    Read the article

  • How to 'insert if not exists' in MySQL?

    - by warren
    I started by googling, and found this article which talks about mutex tables. I have a table with ~14 million records. If I want to add more data in the same format, is there a way to ensure the record I want to insert does not already exist without using a pair of queries (ie, one query to check and one to insert is the result set is empty)? Does a unique constraint on a field guarantee the insert will fail if it's already there? It seems that with merely a constraint, when I issue the insert via php, the script croaks.

    Read the article

  • MacVim commands not working in insert mode

    - by paul smith
    The following shortcuts I have defined in my settings: "Select next/prev tabs noremap <C-Tab> :tabnext<CR> noremap <C-S-Tab> :tabprev<CR> are for going to the previous and next tabs of open files. The only annoying thing about it is anytime I want to switch tabs, I have to first get out of insert mode. How can I force MacVim to register these shortcuts even if I'm in insert mode?

    Read the article

  • Vim quit insert mode when navigate with mapping keys

    - by zdd
    In order to move the cursor in insert mode, I add the following key maps in my .vimrc(I use vim 7.3 on Sun OS) inoremap <Alt-h> <Left> inoremap <Alt-j> <Down> inoremap <Alt-k> <Up> inoremap <Alt-l> <Right> When I press the mapping keys, the cursor moves correct, but vim will quit insert mode and switch to normal mode, what's wrong with my vim? I also tried this with my gvim on Windows, it works well. Did I lost any options for the mapping keys?

    Read the article

  • No Matching Function Error for inserting into a list in c++

    - by Josh Curren
    I am getting an error when I try to insert an item into a list (in C++). The error is that there is no matching function for call to the insert(). I also tried push_front() but got the same error. Here is the error message: main.cpp:38: error: no matching function for call to ‘std::list<Salesperson, std::allocator<Salesperson> >::insert(Salesperson&)’ /usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/bits/list.tcc:99: note: candidates are: std::_List_iterator<_Tp> std::list<_Tp, _Alloc>::insert(std::_List_iterator<_Tp>, const _Tp&) [with _Tp = Salesperson, _Alloc = std::allocator<Salesperson>] /usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/bits/stl_list.h:961: note: void std::list<_Tp, _Alloc>::insert(std::_List_iterator<_Tp>, size_t, const _Tp&) [with _Tp = Salesperson, _Alloc = std::allocator<Salesperson>] Here is the code: #include <stdlib.h> #include <iostream> #include <fstream> #include <string> #include <list> #include "Salesperson.h" #include "Salesperson.cpp" #include "OrderedList.h" #include "OrderedList.cpp" using namespace std; int main(int argc, char** argv) { cout << "\n------------ Asn 8 - Sales Report ------------" << endl; list<Salesperson> s; int id; string fName, lName; int numOfSales; string year; std::ifstream input("Sales.txt"); while( !std::getline(input, year, ',').eof() ) { input >> id; input >> lName; input >> fName; input >> numOfSales; Salesperson sp = Salesperson( id, fName, lName ); s.insert( sp ); //THIS IS LINE 38 ************************** for( int i = 0; i < numOfSales; i++ ) { double sale; input >> sale; sp.sales.insert( sale ); } } cout << endl; return (EXIT_SUCCESS); }

    Read the article

  • how to do multi insert and obtain ids

    - by liysd
    hi, I want to insert some data into a table (id PK autoincrement, val) with use multi insert INSERT INTO tab (val) VALUES (1), (2), (3) Is it possible to obtain a table of last inserted ids? I'm asking becouse I'm not sure if all will in this form: (n, n+1, n+2). I use mysql inodb.

    Read the article

  • NHibernate + Cannot insert the value NULL into...

    - by mybrokengnome
    I've got a MS-SQL database with a table created with this code CREATE TABLE [dbo].[portfoliomanager]( [idPortfolioManager] [int] NOT NULL PRIMARY KEY IDENTITY, [name] [varchar](45) NULL ) so that idPortfolioManager is my primary key and also auto-incrementing. Now on my Windows WPF application I'm using NHibernate to help with adding/updating/removing/etc. data from the database. Here is the class that should be connecting to the portfoliomanager table namespace PortfolioManager { [Class(Table="portfoliomanager",NameType=typeof(PortfolioManagerClass))] public class PortfolioManagerClass { [Id(Name = "idPortfolioManager")] [Generator(1, Class = "identity")] public virtual int idPortfolioManager { get; set; } [NHibernate.Mapping.Attributes.Property(Name = "name")] public virtual string name { get; set; } public PortfolioManagerClass() { } } } and some short code to try and insert something PortfolioManagerClass portfolio = new PortfolioManagerClass(); Portfolio.name = "Brad's Portfolios"; The problem is, when I try running this, I get this error: {System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'idPortfolioManager', table 'PortfolioManagementSystem.dbo.portfoliomanager'; column does not allow nulls. INSERT fails. The statement has been terminated... with an outer exception of {"could not insert: [PortfolioManager.PortfolioManagerClass][SQL: INSERT INTO portfoliomanager (name) VALUES (?); select SCOPE_IDENTITY()]"} I'm hoping this is the last error I'll have to solve with NHibernate just to get it to do something, it's been a long process. Just as a note, I've also tried setting Class="native" and unsaved-value="0" with the same error. Thanks! Edit: Ok removing the 1, from Generator actually allows the program to run (not sure why that was even in the samples I was looking at) but it actually doesn't get added to the database. I logged in to the server and ran the sql server profiler tool and I never see the connection coming through or the SQL its trying to run, but NHibernate isn't throwing an error anymore. Starting to think it would be easier to just write SQL statements myself :(

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >