ソースを参照

完成度表迁移到pg

visuddhinanda 4 年 前
コミット
b5eda4786d

+ 1 - 1
app/palicanon/book_tag.php

@@ -61,7 +61,7 @@ foreach ($output as $key => $value) {
                     }
                 }
             } else {
-                $query = "SELECT lang, all_trans from progress_chapter where book=? and para=?";
+                $query = "SELECT lang, all_trans from "._TABLE_PROGRESS_CHAPTER_." where book=? and para=?";
                 $stmt = $dbh_toc->prepare($query);
                 $sth_toc = $dbh_toc->prepare($query);
                 $sth_toc->execute(array($book, $para));

+ 1 - 1
app/palicanon/get_chapter_children.php

@@ -55,7 +55,7 @@ if ($paraInfo) {
                     }
                 }
             } else {
-                $query = "SELECT lang, all_trans from progress_chapter where book=? and para=?";
+                $query = "SELECT lang, all_trans from "._TABLE_PROGRESS_CHAPTER_." where book=? and para=?";
                 $stmt = $dbh_toc->prepare($query);
                 $sth_toc = $dbh_toc->prepare($query);
                 $sth_toc->execute(array($value["book"], $value["para"]));

+ 1 - 1
app/palicanon/get_chapter_info.php

@@ -45,7 +45,7 @@ if ($paraInfo) {
         }
 
     } else {
-        $query = "SELECT lang, all_trans from progress_chapter where book=? and para=?";
+        $query = "SELECT lang, all_trans from "._TABLE_PROGRESS_CHAPTER_." where book=? and para=?";
         $stmt = $dbh_toc->prepare($query);
         $sth_toc = $dbh_toc->prepare($query);
         $sth_toc->execute(array($book, $para));

+ 4 - 4
app/upgrade/pali_toc_create.php

@@ -1,9 +1,9 @@
 <?php
-#升级段落完成度数据库
+#建立段落完成度数据库
 require_once '../path.php';
 
-$dns = "" . _FILE_DB_PALI_TOC_;
-$dbh_toc = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+$dns = _FILE_DB_PALI_TOC_;
+$dbh_toc = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
 $dbh_toc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
 //建立数据库
@@ -13,4 +13,4 @@ $_arr = explode(';', $_sql);
 foreach ($_arr as $_value) {
     $dbh_toc->query($_value . ';');
 }
-echo $dns . "建立数据库成功";
+echo "建立数据库成功";

+ 17 - 17
app/upgrade/upgrade_pali_toc.php

@@ -1,9 +1,9 @@
 <?php
 #升级段落完成度数据库
 require_once '../path.php';
+require_once '../redis/function.php';
 
-$redis = new redis();
-$r_conn = $redis->connect('127.0.0.1', 6379);
+$redis = redis_connect();
 
 $dns = _FILE_DB_PALI_TOC_;
 $dbh_toc = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
@@ -37,16 +37,16 @@ $stmt->execute();
 $result_lang = $stmt->fetchAll(PDO::FETCH_ASSOC);
 echo "lang:" . count($result_lang) . "<br>\n";
 
-$query = "DELETE FROM progress WHERE 1";
+$query = "DELETE FROM "._TABLE_PROGRESS_." WHERE true";
 $sth_toc = $dbh_toc->prepare($query);
 $sth_toc->execute();
-$query = "DELETE FROM progress_chapter WHERE 1";
+$query = "DELETE FROM "._TABLE_PROGRESS_CHAPTER_." WHERE true";
 $sth_toc = $dbh_toc->prepare($query);
 $sth_toc->execute();
 
 /* 开始一个事务,关闭自动提交 */
 $dbh_toc->beginTransaction();
-$query = "INSERT INTO progress (book, para , lang , all_strlen , public_strlen) VALUES (?, ?, ? , ? ,? )";
+$query = "INSERT INTO "._TABLE_PROGRESS_." (book, para , lang , all_strlen , public_strlen) VALUES (?, ?, ? , ? ,? )";
 $sth_toc = $dbh_toc->prepare($query);
 foreach ($result_lang as $lang) {
     # 第二步 生成para progress 1,2,15,zh-tw
@@ -67,7 +67,7 @@ foreach ($result_lang as $lang) {
             echo "book:{$para["book"]} para: {$para["paragraph"]}\n";
             #查询这些句子的总共等效巴利语字符数
             $place_holders = implode(',', array_fill(0, count($result_sent), '?'));
-            $query = "SELECT sum(length) as strlen from "._TABLE_PALI_SENT_." where book = ? and paragraph = ? and begin in ($place_holders)";
+            $query = "SELECT sum(length) as strlen from "._TABLE_PALI_SENT_." where book = ? and paragraph = ? and word_begin in ($place_holders)";
             $sth = $dbh_pali_sent->prepare($query);
             $param = array();
             $param[] = $para["book"];
@@ -83,13 +83,12 @@ foreach ($result_lang as $lang) {
             } else {
                 $para_strlen = 0;
             }
-            if ($r_conn) {
-				if($redis){
-                	$redis->hSet("progress_{$para["book"]}-{$para["paragraph"]}", $lang["language"], $para_strlen);
-				}
-            } else {
-                $sth_toc->execute(array($para["book"], $para["paragraph"], $lang["language"], $para_strlen, 0));
-            }
+			if($redis){
+				$redis->hSet("progress_{$para["book"]}-{$para["paragraph"]}", $lang["language"], $para_strlen);
+			}
+			{
+				$sth_toc->execute(array($para["book"], $para["paragraph"], $lang["language"], $para_strlen, 0));
+			}
         }
     }
 }
@@ -104,7 +103,7 @@ if (!$sth_toc || ($sth_toc && $sth_toc->errorCode() != 0)) {
 #第三步生成 段落完成度库
 /* 开始一个事务,关闭自动提交 */
 $dbh_toc->beginTransaction();
-$query = "INSERT INTO progress_chapter (book, para , lang , all_trans,public) VALUES (?, ?, ? , ? ,? )";
+$query = "INSERT INTO "._TABLE_PROGRESS_CHAPTER_." (book, para , lang , all_trans,public) VALUES (?, ?, ? , ? ,? )";
 $sth_toc = $dbh_toc->prepare($query);
 
 foreach ($valid_book as $key => $book) {
@@ -125,7 +124,7 @@ foreach ($valid_book as $key => $book) {
             # 译文等效字符数
             foreach ($result_lang as $lang) {
 
-                if ($r_conn) {
+                if ($redis) {
                     $tran_strlen = 0;
                     for ($i = $chapter["paragraph"]; $i < (int) $chapter["paragraph"] + (int) $chapter["chapter_len"]; $i++) {
                         # code...
@@ -138,8 +137,9 @@ foreach ($valid_book as $key => $book) {
                         $progress = $tran_strlen / $pali_strlen;
                         $redis->hSet("progress_chapter_{$book["book"]}_{$chapter["paragraph"]}", $lang["language"], $progress);
                     }
-                } else {
-                    $query = "SELECT sum(all_strlen) as all_strlen from progress where book = ? and (para between ? and ? )and lang = ?";
+                } 
+				{
+                    $query = "SELECT sum(all_strlen) as all_strlen from "._TABLE_PROGRESS_." where book = ? and (para between ? and ? )and lang = ?";
                     $stmt = $dbh_toc->prepare($query);
                     $stmt->execute(array($book["book"], $chapter["paragraph"], (int) $chapter["paragraph"] + (int) $chapter["chapter_len"] - 1, $lang["language"]));
                     $result_chapter_trans_strlen = $stmt->fetch(PDO::FETCH_ASSOC);

+ 1 - 0
db/sqlite/progress/down.sql

@@ -0,0 +1 @@
+DROP TABLE progress ;

+ 12 - 0
db/sqlite/progress/up.sql

@@ -0,0 +1,12 @@
+-- 表:progress
+CREATE TABLE progress 
+(
+	id SERIAL PRIMARY KEY,
+	book INTEGER, 
+	para INTEGER, 
+	lang VARCHAR (16), 
+	all_strlen INTEGER, 
+	public_strlen INTEGER,
+	created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+

+ 1 - 0
db/sqlite/progress_chapter/down.sql

@@ -0,0 +1 @@
+DROP TABLE progress_chapter ;

+ 13 - 0
db/sqlite/progress_chapter/up.sql

@@ -0,0 +1,13 @@
+
+-- 表:progress_chapter
+CREATE TABLE progress_chapter 
+(
+	id SERIAL PRIMARY KEY,
+	book INTEGER, 
+	para INTEGER, 
+	lang VARCHAR (16), 
+	all_trans REAL, 
+	public REAL,
+	created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+