21 * MySQL_Escape_String()
26 この関数の使用前に mysqllib.ring ライブラリを読み込みます。
34 pair: MySQL 関数; MySQL_Info()
39 MySQL_Info() 関数は MySQL クライアントのバージョンを取得します。
45 MySQL_Info() ---> MySQL のバージョン文字列
51 see "MySQL Client Version : " + mysql_info()
57 MySQL Client Version : 6.1.5
60 pair: MySQL 関数; MySQL_Init()
65 MySQL_Init() 関数により MySQL クライアントを使用します。
71 MySQL_Init() ---> MySQL ハンドル
74 pair: MySQL 関数; MySQL_Error()
77 ======================
79 MySQL_Error() 関数は MySQL クライアントからエラーメッセージを取得します。
85 MySQL_Error(MySQL ハンドル) ---> エラーメッセージの文字列
88 pair: MySQL 関数; MySQL_Connect()
91 ========================
93 MySQL_Connect() 関数は MySQL データベースのサーバーへ接続します。
99 MySQL_Connect(MySQL ハンドル, cServer, cUserName, cPassword) ---> lStatus
102 pair: MySQL 関数; MySQL_Close()
105 ======================
107 MySQL_Close() 関数は MySQL データベースの接続を閉じます。
113 MySQL_Close(MySQL ハンドル)
116 pair: MySQL 関数; MySQL_Query()
119 ======================
121 MySQL_Query() 関数は SQL のクエリを実行します。
127 MySQL_Query(MySQL ハンドル, cSQLQuery)
130 pair: MySQL 関数; データベースの作成
135 この用例は MySQL サーバーへ接続後に新しいデータベースを作成します。
139 See "MySQL Test - Create Database" + nl
143 if mysql_connect(con,"localhost","root","root") = 0
144 see "Cann't connect" + nl
145 see "Error : " + mysql_error(con) + nl
150 See "Create Database..." + nl
151 mysql_query(con,"CREATE DATABASE mahdb")
153 See "Close Connection" + nl
160 MySQL Test - Create Database
166 pair: MySQL 関数; テーブルの作成とデータの挿入
169 ============================
171 この用例は新しいテーブルの作成、およびレコードの挿入を行います。
176 see "Create Table and Insert Records" + nl
180 if mysql_connect(con, "localhost", "root", "root","mahdb") = 0
184 see "Drop table" + nl
185 if mysql_query(con, "DROP TABLE IF EXISTS Employee") system_error(con) ok
187 see "Create table" + nl
188 if mysql_query(con, "CREATE TABLE Employee(Id INT, Name TEXT, Salary INT)")
191 see "Insert data" + nl
192 if mysql_query(con, "INSERT INTO Employee VALUES(1,'Mahmoud',15000)")
195 if mysql_query(con, "INSERT INTO Employee VALUES(2,'Samir',16000)")
198 if mysql_query(con, "INSERT INTO Employee VALUES(3,'Fayed',17000)")
201 see "Close connection" + nl
204 func system_error con
205 see mysql_error(con) mysql_close(con) bye
212 Create Table and Insert Records
220 pair: MySQL 関数; MySQL_Inser_ID()
223 ======================
225 MySQL_Insert_ID() 関数は挿入された列の ID を取得します。
231 MySQL_Insert_ID() ---> 数値により挿入された列の ID
238 see "connect to database" + nl
239 mysql_connect(con,"localhost","root","root","mahdb")
240 see "drop table" + nl
241 mysql_query(con, "DROP TABLE IF EXISTS Customers")
242 see "create table" + nl
243 mysql_query(con, "CREATE TABLE Customers(Id INT PRIMARY KEY AUTO_INCREMENT, Name TEXT)")
244 see "insert record" + nl
245 mysql_query(con, "INSERT INTO Customers(Name) VALUES('Mahmoud')")
246 see "insert record" + nl
247 mysql_query(con, "INSERT INTO Customers(Name) VALUES('Samir')")
248 see "insert record" + nl
249 mysql_query(con, "INSERT INTO Customers(Name) VALUES('Fayed')")
250 see "insert record" + nl
251 mysql_query(con, "INSERT INTO Customers(Name) VALUES('Test 2015')")
253 see "inserted row id : " + mysql_insert_id(con) + nl
254 see "close database" + nl
272 pair: MySQL 関数; MySQL_Result()
277 MySQL_Result() 関数はクエリの結果 (カラム名を除くデータ) を取得します。
283 MySQL_Result(MySQL ハンドル) ---> クエリの結果を有するリスト
286 pair: MySQL 関数; MySQL_Next_Result()
288 MySQL_Next_Result() 関数
289 ========================
291 MySQL_Next_Result() 関数は次のクエリの結果を移動します。
292 この関数は同じクエリで複数の SQL ステートメントがあるときに使用します。
298 MySQL_Next_Result(MySQL ハンドル)
301 pair: MySQL 関数; クエリの結果を表示するには
304 ==========================
306 この用例はデータベースでクエリを実行後に結果を表示します。
311 see "Connect to database" + nl
312 mysql_connect(con, "localhost", "root", "root","mahdb")
313 see "Execute Query" + nl
314 mysql_query(con, "SELECT Name FROM Employee WHERE Id=1;"+
315 "SELECT Name FROM Employee WHERE Id=3")
316 see "Print Result" + nl
317 see mysql_result(con)
318 mysql_next_result(con)
319 see mysql_result(con)
320 see "close database" + nl
335 pair: MySQL 関数; MySQL_Columns()
340 MySQL_Columns() 関数はカラム名のリストを取得します。
346 MySQL_Columns(MySQL ハンドル) ---> カラムの情報を有するリスト
353 see "Connect to database" + nl
354 mysql_connect(con, "localhost", "root", "root","mahdb")
355 see "Execute Query" + nl
356 mysql_query(con, "SELECT * FROM Employee")
358 see mysql_columns(con)
359 see "Close database" + nl
384 pair: MySQL 関数; MySQL_Result2()
387 ========================
389 MySQL_Result() でカラム名がないデータの結果を取得するのではなく MySQL_Result2() は、
390 カラム名を全て取得した後にクエリの結果を一つのリストにします。
396 MySQL_Result2(MySQL ハンドル) ---> リスト (カラム名を除いたクエリの結果)
403 see "Connect to database" + nl
404 mysql_connect(con, "localhost", "root", "root","mahdb")
405 see "Execute Query" + nl
406 mysql_query(con, "SELECT * FROM Employee")
407 see "Print Result" + nl
408 see mysql_result2(con)
409 see "Close database" + nl
435 pair: MySQL 関数; MySQL_Escape_String()
437 MySQL_Escape_String() 関数
438 ==========================
440 MySQL_Escape_String() 関数は処理後に、
441 バイナリデータまたは特殊文字をデータベースへ格納します。
447 MySQL_Escape_String(MySQL ハンドル, cString) ---> 処理後の文字列
450 pair: MySQL 関数; データベースのイメージを保存するには
453 ====================================
460 cFile = read("tests\mahmoud.jpg")
462 See "Connect to database..." + nl
463 mysql_connect(con, "localhost", "root", "root","mahdb")
464 See "Escape string..." + nl
465 cFile = mysql_escape_string(con,cFile)
466 stmt = "INSERT INTO photo(id, data) VALUES(1, '" + cFile + "')"
467 See "Insert data..." + nl
468 mysql_query(con,stmt)
469 See "Close database..." + nl
477 Connect to database...
483 pair: MySQL 関数; データベースからイメージを復元するには
486 ======================================
493 See "Connect to database..." + nl
494 mysql_connect(con, "localhost", "root", "root","mahdb")
495 See "Read data from database..." + nl
496 mysql_query(con,"SELECT data FROM photo WHERE id=1")
497 See "Write new file" + nl
498 result = mysql_result(con)
499 write("tests\mahmoud2.jpg",result[1][1])
500 See "Close database..." + nl
507 Connect to database...
508 Read data from database...
514 pair: MySQL 関数; MySQL_AutoCommit()
516 MySQL_AutoCommit() 関数
517 =======================
519 MySQL_AutoCommit() 関数は自動コミット機能の有効、または無効化を指定します。
525 MySQL_AutoCommit(MySQL ハンドル, lStatus) # lStatus には True または False を指定します。
528 pair: MySQL 関数; MySQL_Commit()
531 =======================
533 MySQL_Commit() 関数はデータベースへ更新をコミットします。
539 MySQL_Commit(MySQL ハンドル)
542 pair: MySQL 関数; MySQL_Rollback()
545 =========================
547 MySQL_Rollback() 関数はデータベースのロールバックを更新します。
553 MySQL_Rollback(MySQL ハンドル)
556 pair: MySQL 関数; トランザクションの用例
559 ======================
561 この用例では、 MySQL_Autocommit(), MySQL_Commit() および、
562 MySQL_RollBack() の用法です。
573 if mysql_connect(con, "localhost", "root", "root","mahdb") = 0
576 see "Drop table" + nl
577 if mysql_query(con, "DROP TABLE IF EXISTS Employee2")
580 see "Create table" + nl
581 if mysql_query(con, "CREATE TABLE Employee2(Id INT, Name TEXT, Salary INT)")
584 see "Insert data" + nl
585 if mysql_query(con, "INSERT INTO Employee2 VALUES(1,'Mahmoud',15000)")
588 if mysql_query(con, "INSERT INTO Employee2 VALUES(2,'Samir',16000)")
591 if mysql_query(con, "INSERT INTO Employee2 VALUES(3,'Fayed',17000)")
594 mysql_autocommit(con,False)
595 mysql_query(con, "INSERT INTO Employee2 VALUES(4,'Ahmed',5000)")
596 mysql_query(con, "INSERT INTO Employee2 VALUES(5,'Ibrahim',50000)")
597 mysql_query(con, "INSERT INTO Employee2 VALUES(6,'Mohammed',50000)")
598 See "Save transaction (y/n) " give nChoice
599 if upper(nChoice) = "Y"
605 see "Close connection" + nl
608 func system_error con
622 Save transaction (y/n) y