dbXapp 2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Loading...
Searching...
No Matches
dbxSQLreader.class.php
Go to the documentation of this file.
1<?php
2
3
4
5
6class dbxSQLreader extends dbxObj {
7
8 public function import() {
9
10 $percent=0;
11 $info='import';
12 $oDB = dbx()->get_system_obj('dbxDB');
13
14 $file=$this->get_property('filename','nofile');
15 $errorFile= $file.'.err'; // tmp file for erro
16 $inf = new SplFileInfo($file);
17 $ext = ($inf->getExtension());
18 $max = ini_get('max_execution_time');
19 $this->set_property('max_time',$max);
20 $this->set_property('file_ext',$ext);
21
22 $process = $this->get_property('process','sqlImport');
23 $server = $this->get_property('server', dbx()->get_config('dbx', 'default_server'));
24 $bytes = $this->get_property('run_bytes',96000);
25 $maxRuntime = $this->get_property('run_time',1); // less then your max script execution limit
26 $deadline = time()+$maxRuntime;
27 $filePos = dbx()->get_session_var('filepos',0,$process);
28 $queryCount = $this->get_property('querys',0);
29
30 //dbx_debug("#IMPORT Pos=($filePos)");
31
32 if (!$filePos) $this->set_property('status',0);
33 $queryCount=dbx()->get_session_var('querys',0,$process);
34
35 ($fp = fopen($file, 'r')) OR die('failed to open file:'.$file);
36 if($filePos) fseek($fp, $filePos);
37
38 $filesize=filesize($file);
39 $query = '';
40
41 while( $deadline>time() AND ( $line=fgets($fp, $bytes ) ) ) {
42 if(substr($line,0,2)=='--' OR trim($line)=='') {
43 continue;
44 }
45 $query.= $line;
46
47 if( substr(trim($query),-1)==';' ){
48 $ok=$server ? $oDB->exec($server, $query) : 0;
49 if(!$ok) {
50 $error = $query . $oDB->get_error_text();
51 $errorFile=dbx_os_path_file($errorFile);
52 file_put_contents($errorFile, $error, FILE_APPEND);
53 }
54 $query = ''; $queryCount++;
55 dbx()->set_session_var('filepos',ftell($fp),$process);// save current file position
56 }
57
58 }
59
60 if( feof($fp) ){
61 //dbx()->set_session_var($progress,0);
62 $this->set_property('status',2);
63 $this->set_property('done',$filesize);
64 $this->set_property('percent',100);
65 }else{
66 $done =ftell($fp);
67 $percent =(round($done/$filesize, 2)*100);
68 $this->set_property('status',1);
69 $this->set_property('done',$done);
70 $this->set_property('percent',$percent);
71 dbx()->set_session_var('filepos',$done,$process);
72 }
73 $this->set_property('filesize' ,$filesize);
74 $this->set_property('querys' ,$queryCount);
75 dbx()->set_session_var('querys',$queryCount,$process);
76
77 $status=$this->get_property('status',0);
78
79 //dbx_debug("#dbImport# Status=($status) QeryCount=($queryCount) Filesize=($filesize) Pos ($filePos) Prozent=($percent) ");
80
81
82 if ($status==2) {
83 dbx()->delete_session_var('*',$process);
84 }
85 return $status;
86 } // import
87 // - - - - - - - - - -
88
89
90
91
92
93 public function run() {
94 //$this->init();
95 $ok=$this->import();
96
97 return $ok;
98 }
99}
100
101
102?>
Gemeinsame Basisklasse fuer dbXapp-System-, Modul- und Include-Objekte.
Definition dbxKernel.php:63
get_property($name, $default='', $section='', $modul='modul')
Liest eine Objekt- oder Session-Property.
set_property($name, $value, $section='', $modul='modul')
Speichert eine Objekt- oder Session-Property.
dbx_os_path_file($path_file)
Definition index.php:164
DBX schema administration.