هذه صفحة تحتوي على أفكار خام
استيراد الكتب من الشاملة عبر mdbtools وذلك باستخدام
bash$ mdb-schema file.mdb .... DROP TABLE b2023; CREATE TABLE b2023 ( id Long Integer, nass Memo/Hyperlink (255), part Byte, page Long Integer, hno Long Integer ); ... bash$ mdb-export -I file.mdb Table INSERT INTO Main (BkId, Bk, Betaka, Inf, Auth, AuthInf, TafseerNam, IslamShort) VALUES (2023,"Blah ....
حيث يمكن تحويلها إلى sqlite أو أي قاعدة بيانات أخرى
كان هناك مشكلة في التعامل مع العربية http://sourceforge.net/tracker/index.php?func=detail&aid=741831&group_id=2294&atid=102294
لكنها حلت بعد اعتماد unicode في mdbtools لكن هناك مشكلة أن النص الناتج كان مشوها وغير مقروء
correct: درء تناقض العقل والنقل D8AF D8B1 D8A1 20 D8AA D8B9 D8A7 D8B1 D8B6 20 D8A7 D984 D8B9 D982 D984 20 D988 D8A7 D984 D986 D982 D984 deformed: unreadable utf-8 text C38F C391 C381 20 C38A C39A C387 C391 C396 20 C387 C3A1 C39A C39E C3A1 20 C3A6 C387 C3A1 C3A4 C39E C3A1 correct: 1101-1000-1010-1111 1101-1000-1011-0001 1101-1000-1010-0001 1101-1000-1010-1010 1101-1000-1011-1001 1101-1000-1010-0111 deformed 1100-0011-1000-1111 1100-0011-1001-0001 1100-0011-1000-0001 1100-0011-1000-1010 1100-0011-1001-1010 1100-0011-1000-0111
بعد قراءة الكود تبين أن JET3 المستخدمة في الشاملة لا تعتمد unicode ولا تحدد ال encoding داخل ملف mdb وتبين أن الحل بسيط جدا وهو تمرير الترميز على شكل env
MDB_JET3_CHARSET=cp1256 mdb-export -I file.mdb Table
yum install mdbtools
mdb-schema x.mdb | perl -wpe 's%^DROP TABLE %DROP TABLE IF EXISTS %i;s%Memo/Hyperlink%TEXT%i;s%(Byte|(\w+ )?Integer)%INTEGER%i;s%\s*\(\d+\)\s*(,?[ \t]*)$%${1}%;s%(\s+TEXT)%${1} DEFAULT NULL%;s%(\s+INTEGER)%${1} DEFAULT 0%;' | sqlite3 x.db for i in $(mdb-tables x.mdb); do echo $i; ( echo "BEGIN TRANSACTION;"; MDB_JET3_CHARSET=cp1256 mdb-export -R ";\n" -I x.mdb $i; echo "END TRANSACTION;" ) | sqlite3 x.db; done
هيئة المكتبة الشاملة مشروحة في هذا الرابط http://www.shamela.ws/old_site/help.php?do=database فإذا أردنا تغيير تركيبة قاعدة البيانات نستطيع عمل:
rm x.db ( # create temporary tables schema mdb-schema x.mdb | perl -wpe 's%^DROP TABLE %DROP TABLE IF EXISTS tmp%i;s%^CREATE TABLE %CREATE TEMP TABLE tmp%i;s%Memo/Hyperlink%TEXT%i;s%(Byte|(\w+ )?Integer)%INTEGER%i;s%\s*\(\d+\)\s*(,?[ \t]*)$%${1}%;s%(\s+TEXT)%${1} DEFAULT NULL%;s%(\s+INTEGER)%${1} DEFAULT 0%;'; # import the data base as-is into the temporary tables echo "BEGIN TRANSACTION;"; for i in $(mdb-tables x.mdb); do MDB_JET3_CHARSET=cp1256 mdb-export -R ";\n" -I x.mdb $i; done | perl -l -wpe 's/^INSERT INTO /INSERT INTO tmp/i' # create out own tables format replace tmpb2023 with "tmpb%(id)d" echo "DROP TABLE IF EXISTS bookcontent;" echo "CREATE TABLE bookcontent (id integer PRIMARY KEY, textbody text);" echo "DROP TABLE IF EXISTS toc;" echo "CREATE TABLE toc (id integer PRIMARY KEY AUTOINCREMENT, prev_id integer, next_id integer, level integer, ref text, title text);" echo "INSERT INTO bookcontent (id, textbody) SELECT id,nass FROM tmpb2023 ORDER BY id;" echo "INSERT INTO toc (id, prev_id, next_id, level, ref, title) SELECT t.id, t.id-1,t.id+1, t.lvl, b.page, t.tit FROM tmpt2023 as t,tmpb2023 as b ORDER BY t.id, t.sub limit 1;" echo "END TRANSACTION;" ) | sqlite3 x.db
لكن لسبب ما طريقة الاستيراد هذه أقل سرعة بكثير من سابقتها.
import a shamelah book into a single sqlite file in /var/thwab or /usr/share/thwab/ or in home
and then it touches the top level directory so that when the app checks mtime stamp and it knows that a new files and update ~/.thwab/main.db which have ids titles and topics hierarchy
system wide vs. user specific adding and where caching should be ..etc.
import all books into a single database (in shamelah they call it archive) on /var/thwab/books.db and only those who have write access there can import new files cache, indices …etc all are global
but in this case I think I should make thwab to open not yet imported books but this is not a feature
I'm going the second way