원본 :http://dev.mysql.com/tech-resources/articles/mysql-connector-cpp.html#trx

Using Transactions

A database transaction is a set of one or more statements that are executed together as a unit, so either all of the statements are executed, or none of them are executed. MySQL supports local transactions within a given client session through statements such as SET autocommit, START TRANSACTION, COMMIT, and ROLLBACK.

Disable AutoCommit Mode

By default, all the new database connections are in autocommit mode. In the autocommit mode, all the SQL statements will be executed and committed as individual transactions. The commit occurs when the statement completes or the next execute occurs, whichever comes first. In case of statements that return a ResultSet object, the statement completes when the last row of the ResultSet object has been retrieved or the ResultSet object has been closed.

One way to allow multiple statements to be grouped into a transaction is to disable autocommit mode. In other words, to use transactions, the Connection object must not be in autocommit mode. The Connection class provides the setAutoCommit method to enable or disable the autocommit. An argument of 0 to setAutoCommit() disables the autocommit, and a value of 1 enables the autocommit.

Connection *con;
..
/* disable the autocommit */
con -> setAutoCommit(0);

It is suggested to disable autocommit only while you want to be in transaction mode. This way, you avoid holding database locks for multiple statements, which increases the likelihood of conflicts with other users.

Commit or Rollback a Transaction

Once autocommit is disabled, changes to transaction-safe tables such as those for InnoDB and NDBCLUSTER are not made permanent immediately. You must explicitly call the method commit to make the changes permanent in the database or the method rollback to undo the changes. All the SQL statements executed after the previous call to commit() are included in the current transaction and committed together or rolled back as a unit.

The following code fragment, in which con is an active connection, illustrates a transaction.

Connection *con;
PreparedStatement *prep_stmt;

..
con -> setAutoCommit(0);

prep_stmt = con -> prepareStatement ("INSERT INTO City (CityName) VALUES (?)");

prep_stmt -> setString (1, "London, UK");
prep_stmt -> executeUpdate();

con -> rollback();

prep_stmt -> setString (1, "Paris, France");
prep_stmt -> executeUpdate();

con -> commit();

In this example, autocommit mode is disabled for the connection con, which means that the prepared statement prep_stmt is committed only when the method commit is called against this active connection object. In this case, an attempt has been made to insert two rows into the database using the prepared statement, but the first row with data "London, UK" was discarded by calling the rollback method while the second row with data "Paris, France" was inserted into the City table by calling the commit method.

Another example to show the alternate syntax to disable the autocommit, then to commit and/or rollback transactions explicitly.

Connection *con;
Statement *stmt;

..
stmt = con -> createStatement();

//stmt -> execute ("BEGIN;");
//stmt -> execute ("BEGIN WORK;");
stmt -> execute ("START TRANSACTION;");

stmt -> executeUpdate ("INSERT INTO City (CityName) VALUES ('London, UK')");
stmt -> execute ("ROLLBACK;");

stmt -> executeUpdate ("INSERT INTO City (CityName) VALUES ('Paris, France')");
stmt -> execute ("COMMIT;");

The START TRANSACTION or BEGIN statement starts a new transaction. COMMIT commits the current transaction to the database by making the changes permanent. ROLLBACK rolls back the current transaction by canceling the changes to the database. With START TRANSACTION, autocommit remains disabled until you end the transaction with COMMIT or ROLLBACK. The autocommit mode then reverts to its previous state.

BEGIN and BEGIN WORK are supported as aliases of START TRANSACTION for initiating a transaction. START TRANSACTION is standard SQL syntax and it is the recommended way to start an ad-hoc transaction.

Rollback to a Savepoint within a Transaction

The MySQL connector for C++ supports setting savepoints with the help of Savepoint class, which offer finer control within transactions. The Savepoint class allows you to partition a transaction into logical breakpoints, providing control over how much of the transaction gets rolled back.

As of this writing, InnoDB and Falcon storage engines support the savepoint transactions in MySQL 6.0.

To use transaction savepoints, the Connection object must not be in autocommit mode. When the autocommit is disabled, applications can set a savepoint within a transaction and then roll back all the work done after the savepoint. Note that enabling autocommit invalidates all the existing savepoints, and the Connector/C++ driver throws an InvalidArgumentException when an attempt has been made to roll back the outstanding transaction until the last savepoint.

A savepoint is either named or unnamed. You can specify a name to the savepoint by supplying a string to the Savepoint::setSavepoint method. If you do not specify a name, the savepoint is assigned an integer ID. You can retrieve the savepoint name using Savepoint::getSavepointName().

Signatures of some of the relevant methods are shown below. For the complete list of methods supported by Connection, Statement, PreparedStatement and Savepoint interfaces, check the connection.h, statement.h and prepared_statement.h headers in your Connector/C++ installation.

/* connection.h */
Savepoint* Connection::setSavepoint(const std::string& name);
void Connection::releaseSavepoint(Savepoint * savepoint);
void Connection::rollback(Savepoint * savepoint);

The following code fragment inserts a row into the table City, creates a savepoint SAVEPT1, then inserts a second row. When the transaction is later rolled back to SAVEPT1, the second insertion is undone, but the first insertion remains intact. In other words, when the transaction is committed, only the row containing "London, UK" will be added to the table City.

Connection *con;
PreparedStatement *prep_stmt;
Savepoint *savept;

..
prep_stmt = con -> prepareStatement ("INSERT INTO City (CityName) VALUES (?)");

prep_stmt -> setString (1, "London, UK");
prep_stmt -> executeUpdate();

savept = con -> setSavepoint ("SAVEPT1");

prep_stmt -> setString (1, "Paris, France");
prep_stmt -> executeUpdate();

con -> rollback (savept);
con -> releaseSavepoint (savept);

con -> commit();

The method Connection::releaseSavepoint takes a Savepoint object as a parameter and removes it from the current transaction. Any savepoints that have been created in a transaction are automatically released and become invalid when the transaction is committed, or when the entire transaction is rolled back. Rolling back a transaction to a savepoint automatically releases and invalids any other savepoints that were created after the savepoint in question. Once a savepoint has been released, any attempt to reference it in a rollback operation causes the SQLException to be thrown.

Posted by 지누구루

이번 주말에 쉬면서 뭘 볼까 하고 검색하다가
그냥 눈에 띄인것도 있고.
포스터가 맘에 든 것도 있고.
하도 재밌다는 글이 많이 보인 것도 있고 해서
받아 두었다가.
일욜밤에 틀었는데
... 결국 스트레이트로 다 봤습니다.
(그래서... 밤 10시 이후에 틀지 말란 이야기가 있었던 거더라구요...)

스토리 설명이나. 그런건 다른 검색을 참고 하시고.

보고 난 뒤에 매우 여운이 깊게 남긴 했는데.
도무지 해결되지 않는 의문점들이 꽤 많아서.
정리 해 두려고 합니다.
(혹시나 나중에 명쾌한 해석이라도 찾게 되면 기억이 나야 하니까용)
(예전에 비슷한 이유로 괭이 갈매기 울적에의 의문점을 정리한 적이 있는데 아직 해답편이 안나왔네요)




아래 내용은 드라마를 보시지 않은 분들은 보지 않으시길.

중간부분에서의 의문 보단. 결말에 가까운 시점에서의 의문들이 많습니다.


1) 과거 컬렉터즈의 콘로이가 여러 오브젝트를 이용해서 9호실 문을 열었을때의 상황이 명확하지 않음

내용을 보면 여러 오브젝트간의 상호 작용에 의해서 어떤 현상이 일어 났고.
그 결과 콘로이는 알수 없는 공간에 갇히게 되며
해당 사건때 보유자. 에 의해서 중지 된 것으로 나옵니다.

하지만 결국 그 오브젝트들에 연관에 의해 일어난 일이 뭔지 안나옵니다.
그래서 마지막에 같은 오브젝트를 사용하여 문을 연 크로이츠펠드? 가 어떻게 된건지
정확하게 알 수가 없습니다.
(콘로이의 경우처럼 귀신처럼 된건지 말이졍)

잘 생각해보면 그렇게 이상해진 방에 보유자와 밀러가 들어가면 다시 10호 방인 것도.
조금 설정상 안맞지 않나 싶기도 합니다.


2) 오브젝트 예언자?

사막에서 죽을뻔하다 구출된  마틴 루버. 저는 사실 그냥 미친건줄 알았는데.
뒤에 보면 그 형사의 꿈 내용을 맞추거나 다른 상황을 그냥 알고 있는 내용이 있습니다.
얘는 왜 이렇게 된건지.
예언자? 라는 것의 역할은 무엇인지 전혀 안나오고 끝나 버립니다-_-+


3) 제가 말도 안된다고 생각한 오브젝트 추적 지도...

수드? 였나. 컴퓨터로 오브젝트 위치를 다 추적하는 내용이 나오는데.
그게 되는 이율 모르겠네요.
마지막에 오브젝트끼리 교신하는 신호 같은게 있다는 내용이 있는데.
그걸 추적하는 시스템을 전세계에 구축해놨다는 걸까요-_-+
(이건 아마... 제 직업상... 어이 없다고 느낀 부분이랄까.. 그렇습니다)


4) 말이 많은 마지막 지워지지 않은 기억...

기존의 보유자는 자신이 오브젝트가 되면서 세계에서 자신이 지워졌지만
조 밀러는 어떻게 될지 알수 없다고 했고.
결과적으로는 밀러는 세상에서 지워지지 않았습니다.
뭐 일단 이 부분에 대해서는 보유자가 "자신도 모르겠다" 라고 했으니
그렇다 치고 넘어 갑시다.

저는 개인적으로 결국 밀러도 세상에서 지워지고.
딸만 기억이 지워진채 세상으로 돌아오는 엔딩을 매우 기대했는데 말입니다 ㅠㅠ


5) 마지막 장면의 열쇠가 리셋되지 않은 것?

사실 저는 이 부분이 궁금하지 않았는데.
지식인에 보니까 저 부분에 대한 의문을 품는 분들이 많더라구요.

사실 이 드라마에는 충분한 설명을 하지 않고 "대충" 때우고 넘어간 부분이 있습니다.
뒤를 보다 보면 그부분에 대한 설정이 없는 것은 아닌데.
짧은 시간에 제한된 내용을 만들다 보니 친절하게 설명을 다 못해준것이 아닌가 하고 생각하는데요.

이 부분에 대한 제 생각은
[1] 그냥 넣은 엔딩 장면. 영화에서 가장 의미 있었던 오브젝트.
[2] 다음 시즌에 대한 암시

정도로 생각했는데.
시즌2가 없네요-_-+

일단 돌아다니는 이야기 중엔.
"마지막에 오브젝트가 된 '조 밀러'가 던져 넣었기 떄문" 이 가장 힘있는 주장이라고.
저는 생각합니다.


6) 제가 놓친 것인지 정확하게 판단이 안되긴 하는데. 보유자를 찾아가는 부분

보유자를 추적하다가. 보유자가 세계에서 지워지기 전 아내를 찾아가서 그에 대해 물어 보는 부분.
분명히 이름을 기억하지 못하고 있는데.

사막의 그를 찾아가는데.
[1] 그 근처란것만 알지 정확히 어느 위치에 그가 있는진 모르는데 '정신 병원'을 한방에 찾아감
[2] 그리고 그전까지 한번도 언급이 없었던 '존 도' 라는 이름으로 한번에 찾음.

.... 제가 놓친건지 모르겠는데.
제 기억엔 저 데이터를 얻는 내용이 없었습니다.


7) 결국. 1961년의 그날. 그 방에서는 무슨 일이 있었나?

잘생각해보면 1961년 그날 원래 "보유자"는 버스를 타고 그곳으로 건너와서.
모텔에 숙박을 하려 했는데 그곳에서 뭔가 일이 일어났다.
라고 볼수 있습니다.

중간에 보면 "원래 그 모텔은 9호실까지 밖에 없었다" 란 말이 있습니다.
이건 제 추측이지만.
원래는 1호실까지 있었는데 그날 있었던 어떤 일로 인해 10호실 전체(안에 있던 모든것까지)가
세상에서 지워진 것. 이라고 생각됩니다.
(그래서 제목도 The Lost Room 이라고 생각합니다. 없어진 방이니까요)

하지만 결국. 그날 무슨일이 있었는지는 알수가 없습니다.
(첨부터 이건 알려주지 않을 생각이었던거 같습니다. 그냥 초자연현상이 있었음!! 이런걸로 끝인듯)


이정도입니다.

오랜만에 무척 몰입되면서.
중간중간에 오브젝트를 적재 적소에 사용하는 부분들은.
일종의 어드벤쳐 게임의 퍼즐을 맞추는 기분이 들게도 했습니다.

안보신 분들은 꼭 한번 보시길...이라고 생각하지만.
여기까지 읽으셨으면 이미 보신 분들이겠지요. ㅎㅎ

내일은 연차니까
이제 자겠습니다!!!

Posted by 지누구루
◀ PREV : [1] : [2] : [3] : [4] : [5] : ... [47] : NEXT ▶

BLOG main image
by 지누구루

공지사항

카테고리

분류 전체보기 (93)
자유글 (9)
공부 (6)
JProject (0)
게임 (33)

글 보관함

달력

«   2012/01   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Total : 66,425
Today : 16 Yesterday : 15