function add_word($name) { global $sql_stmts; $w = defaultDB()->searcher()->name($name)->spart("verb")->lang("la")->all(); if (count($w)) { echo "Word seems to be already added: {$name}<br>"; if (count($w) === 1) { $w = $w[0]; if ($w->read_paths()) { echo "- Had inflection already<br>"; } else { return $w; } } else { echo "- More than one found, continuing<br>"; } } else { echo "Adding word: {$name}<br>"; sql_exec(sql_stmt("word_lang,word_name,word_spart->new in words"), ["sss", "la", $name, "verb"]); $w = defaultDB()->searcher()->name($name)->spart("verb")->lang("la")->all(); if (count($w) === 1) { $w = $w[0]; return $w; } } }
function remove() { global $sql_stmts; if ($this->issql and $this->_id !== NULL) { return sql_exec(sql_stmt("pron_id->delete from pronunciations"), ["i", &$this->_id]); } # still NULL if not found }
function admin_getpaypaltransactions($currency = false, $from = false, $to = false) { $qu = sql_exec("select xid,min(time) as time," . "subtract_money('',sum_money(change)) as change " . "from transaction_log where " . "xid in (select xid from transaction_log where " . "(account like 'anon-deposits:%' or " . "account like 'deposits:%' or " . "account like 'subscription-payments:%' or " . "account like 'withdrawals:%')" . ($currency === false ? "" : " and change like '%" . sql_escape($currency) . "'") . ($from === false ? "" : " and time >= " . intval($from)) . ($to === false ? "" : " and time < " . intval($to)) . ") and (account like 'anon-deposits:%' or " . "account like 'deposits:%' or " . "account='paypal-fee' or " . "account like 'subscription-payments:%' or " . "account like 'withdrawals:%') " . "group by xid order by xid"); if ($qu === false) { return private_dberr(); } $transactions = array(); for ($i = 0; $i < sql_numrows($qu); $i++) { $row = sql_fetch_array($qu, $i); $transactions[intval($row["xid"])] = array("xid" => intval($row["xid"]), "time" => intval($row["time"]), "change" => "{$row['change']}"); } return array(0, $transactions); }
function make_word($name, $jp = NULL, $zh = NULL) { global $sql_stmts; sql_exec(sql_stmt("word_lang,word_name,word_spart->new in words"), ["sss", "tp", $name, "multi"]); $id = NULL; sql_getone(sql_stmt("word_lang,word_name,word_spart->word_id"), $id, ["sss", "tp", $name, "multi"]); $GLOBALS["word"] = WORD(defaultDB(), $id); if ($jp) { $a = ATTR("jp", $jp); $GLOBALS["word"]->add_attr($a); } if ($zh) { $a = ATTR("zh", $jp); $GLOBALS["word"]->add_attr($a); } }
function add_word($name) { global $sql_stmts; $w = defaultDB()->searcher()->name($name)->spart("verb")->lang("la")->all(); if (count($w)) { echo "Word seems to be already added: {$name}<br>"; return NULL; } else { echo "Adding word: {$name}<br>"; sql_exec(sql_stmt("word_lang,word_name,word_spart->new in words"), ["sss", "la", $name, "verb"]); $w = defaultDB()->searcher()->name($name)->spart("verb")->lang("la")->all(); if (count($w) === 1) { $w = $w[0]; return $w; } } }
if (!array_key_exists("name", $_GET)) { $_GET["name"] = NULL; } if (!array_key_exists("spart", $_GET)) { $_GET["spart"] = NULL; } foreach ($_GET as $k => $v) { if (!startswith($k, "delete_")) { continue; } if ($v != "true") { continue; } $id = explode("_", $k, 2)[1]; $id = intval($id); sql_exec(sql_stmt("form_id->delete from forms"), ["i", $id]); } $list = $db->find_all_words($_GET["name"], $_GET["lang"], $_GET["spart"]); foreach ($list as $w) { ?> <ul><?php display_word_info($w); ?> <br><?php $id = $w->id(); $w->read_paths(); foreach ($w->paths() as $path) { echo "<li>[" . $path->id() . "] ({$path})" . $path->value(); echo " <button onclick='moveloc(" . $path->id() . ")'>Delete</button><br>"; } ?>
} $definitions = safe_get("definitions", $_GET); $connections = safe_get("connections", $_GET); $forms = safe_get("forms", $_GET); if (!requireRank(3, FALSE)) { echo "Insufficient permissions"; } else { if ($langs and count($langs) == 1 and $names and count($names) == 1 and $sparts and count($sparts) == 1) { $w = defaultDB()->searcher()->name($names[0])->spart($sparts[0])->lang($langs[0])->all(); if (count($w)) { exit("Word seems to be already added. <a href='/dictionary.php?lang={$langs[0]}&spart={$sparts[0]}&name={$names[0]}' target='_blank'>See it</a>"); } if (!$definitions or !count($definitions)) { exit("Please enter at least one definition"); } sql_exec(sql_stmt("word_lang,word_name,word_spart->new in words"), ["sss", $langs[0], $names[0], $sparts[0]]); $w = defaultDB()->searcher()->name($names[0])->spart($sparts[0])->lang($langs[0])->all(); if (count($w) === 1) { $w = $w[0]; foreach ($attrs as $a) { error_log($a); $a = explode("=", $a, 2); if (count($a) === 2) { $w->add_attr(ATTR($a[0], $a[1])); } } foreach ($definitions as $d) { $dd = DEFINITION(defaultDB(), NULL, $w); $dd->set_lang("en"); $dd->set_value($d); $w->add_definition($dd);
function error() { sql_exec("rollback"); exit; }
function delete() { sql_exec(sql_stmt("quiz_id->delete from quizzes"), ["i", &$this->_id]); return TRUE; }
/** * Load resource data (from datapackage or $etc). * @param $basePath array of SQL blocks * @param $items array of pairs command-param * @param $MSG a general message or items-description. * @param $etc string ($jfieldName) or array with replacement for datapackage. */ function resourceLoad_run($basePath, $items, $MSG = '', $etc = 'jinfo') { global $db; if (is_array($etc)) { // a datapackage replacement $packs = $etc['packs']; $jfieldName = $etc['jfieldName']; } else { $jfieldName = $etc; $packs = unpack_datapackage($basePath); // mais de uma } $time_start = microtime(true); print "\n\tBEGIN processing {$MSG} ..."; $affected = 0; foreach ($items as $resName => $preps) { foreach ($preps as $args) { if (isset($packs[$resName])) { $cmd = array_shift($args); print "\n\t... Running {$resName} with '{$cmd}'"; $p = $packs[$resName]; // with-wrap $is_jsonb = false; switch ($cmd) { case 'prepared_copy': // the target table was prepared before. arg1=table name. $sql = "COPY {$args['0']} FROM '{$p['file']}' DELIMITER '{$p['sep']}' CSV HEADER;"; $affected += sql_exec($db, $sql, "\n\t... {$cmd}({$args['0']}) "); break; default: // automatic, creating table as tmp_name $cmd = 'prepare_auto'; case 'prepare_jsonb': $is_jsonb = $cmd != 'prepare_auto'; // true // true case 'prepare_auto': case 'prepare_json': // the target table will be created. arg1=table name. $fields0 = join(' text, ', $p['fields_sql']) . ' text'; $fields2 = $fields0b = $fields3 = $fields3s = ''; $fields1 = join(',', $p['fields_sql']); if (count($p['fields_json'])) { $fields0b = ", {$jfieldName} JSON" . ($is_jsonb ? 'B' : ''); $fields1x = $fields1 . ", {$jfieldName}"; $fields2 = ", " . join(' Text, ', $p['fields_json']) . ' text'; $fields3 = join(',', $p['fields_json']); $fields3s = "'" . join("','", $p['fields_json']) . "'"; } $sql = "CREATE TABLE {$args['0']} (id serial PRIMARY KEY, {$fields0}{$fields0b});"; if (count($p['fields_json'])) { $sql .= "CREATE TABLE {$args[0]}_tmp ({$fields0}{$fields2});"; } $affected += sql_exec($db, $sql, "\n\t... creating table..."); if (count($p['fields_json'])) { $sql = "COPY {$args[0]}_tmp FROM '{$p['file']}' DELIMITER '{$p['sep']}' CSV HEADER;"; $affected += sql_exec($db, $sql, "\n\t... loading tmp {$cmd}({$args['0']}) "); if ($is_jsonb) { $pairs = []; for ($i = 0; $i < count($p['fields_json']); $i++) { if ($p['fields_json'][$i]) { $pairs[] = "'{$p['fields_json'][$i]}',{$p['fields_json'][$i]}::" . json2sqltype($p['fields_json_types'][$i]); } } $pairs = join(', ', $pairs); $sql = "INSERT INTO {$args[0]} ({$fields1x})\n\t\t\t\t\t\t\t SELECT {$fields1},jsonb_build_object({$pairs})\n\t\t\t\t\t\t\t FROM {$args[0]}_tmp;\n\t\t\t\t\t\t\t"; } else { $sql = "INSERT INTO {$args[0]} ({$fields1x})\n\t\t\t\t\t\t\t SELECT {$fields1},json_object(array[ {$fields3s} ],array[ {$fields3} ])\n\t\t\t\t\t\t\t FROM {$args[0]}_tmp;\n\t\t\t\t\t\t\t"; } $affected += sql_exec($db, $sql, "\n\t... INSERT tmp ... "); $affected += sql_exec($db, "DROP TABLE {$args[0]}_tmp;", "\n\t... DROP tmp ... "); } break; case 'commom': // standad _tmp table die("\nOOPS under construction"); break; } // switch $time_end = microtime(true); $execution_time = round($time_end - $time_start, 2); print "\n\tEND PROCESSING (acum. {$affected} rows affected) spending {$execution_time} seconds.\n"; } else { die("\n\t-- BUG: items requerindo '{$resName}' inexistente no Pack\n"); } } } //var_dump($packs); }
function remove($hash = NULL) { global $sql_stmts; if ($this->issql and $this->_id !== NULL) { sql_exec(sql_stmt("form_id->delete from forms"), ["i", &$this->_id]); } $hash =& $this->resolve_hash($hash); if (FLAT_STORAGE) { $ret = $hash[(string) $this]; unset($hash[(string) $this]); return $ret; } $h = $this->walk($hash, 0); if ($h === NULL) { return NULL; } $this->_map_dirty = 1; $r = $h[""]; unset($h[""]); # Clean up dead branches if we have killed them: while (!count($h) and count($this)) { $max = count($this) - 1; list($h2, $i, $k) = $this->walk_part($hash, $max); assert('$this->map[$i] == $k'); assert('$h == $h2[$k]'); unset($h2[$k]); $h = $h2; } return $r; }
function move2($old, $new, $table2, $column, $safe) { global $mysqli; move($old, $safe, $table2, $column); $stmt = $mysqli->prepare("UPDATE {$table2} SET {$column} = {$column} + 1 WHERE {$column} >= ? AND {$column} < ?"); if (!$stmt) { echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; } sql_exec($stmt, ["ii", $new, $old]); $stmt = $mysqli->prepare("UPDATE {$table2} SET {$column} = ? WHERE {$column} = ?"); if (!$stmt) { echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; } sql_exec($stmt, ["ii", $new, $safe]); $stmt->close(); }
* See also scripts at "ini.sql" (run it first!). * php openness-metrics/src/php/ini.php */ include 'omLib.php'; $verbose = 1; // 0,1 or 2 // include 'doaj_get.php'; // for check openness degree of citations in sciDocs. // // // // // // // // // // // CONFIGS: (complement to omLib) $projects = ['licences' => '/home/peter/gits/licenses', 'openness-metrics' => '/home/peter/gits/openness-metrics']; $reini = true; // re-init all SQL structures of the project (drop and refresh schema) // // // // // // SQL PREPARE $items = ['openness-metrics' => [array('INSERT INTO om.license_families(fam_name,fam_info) VALUES (:family::text, :json_info::JSONB)', 'families.csv::strict')], 'licences' => [array('SELECT om.licenses_upsert( :id_label::text, :id_version::text, :name::text, :family::text, NULL::text, :json_info::jsonB )', 'implieds.csv::bind', 'licenses.csv::bind'), array('SELECT om.licenses_upsert( :id_label::text, :id_version::text, :name::text, :family::text, :name_of_equiv::text, :json_info::jsonB )', 'redundants.csv::bind')]]; $sql_delete = " -- prepare to full refresh of om.scheme\n\tDELETE FROM om.licenses WHERE substring(lic_id_label,1,1)!='(';\n\tDELETE FROM om.license_families WHERE substring(fam_name,1,1)!='(';\n"; // // // // INITS: //FALTA informar do erro de um exec. $db = new pdo($dsn, $PG_USER, $PG_PW); if ($reini) { sql_exec($db, file_get_contents($projects['openness-metrics'] . '/src/ini.sql')); } sql_exec($db, $sql_delete); print "BEGIN processing ..."; list($n2, $n, $msg) = jsonCsv_to_sql($items, $projects, $db, ',', 0, $verbose); print "{$msg}\n\nEND(tot {$n} lines scanned, {$n2} lines used)\n";
} } if ($e) { echo "<br>"; } $last = 0; for ($id = 1; $id <= $max_id; $id++) { if (!array_key_exists($id, $ids)) { if ($e) { echo "{$id} missing<br> "; } } else { if ($last !== NULL and $last !== $id - 1) { $stmt = $mysqli->prepare("UPDATE {$table2} SET {$column} = ? WHERE {$column} = ?"); if (!$stmt) { echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; echo "\nStatement was: " . var_export($value, 1); } sql_exec($stmt, ["ii", $last + 1, $id]); $stmt->close(); if ($e) { echo "{$id} -> " . ($last + 1) . "<br> "; } } $last += 1; } } echo "1 through {$last}"; $time = microtime(true) - $start; $time = round($time, 1); echo "<br><hr>Took {$time} seconds";
function sql_set($stmt, $result, $params) { $params[0] = "s" . $params[0]; array_splice($params, 1, 0, [$result]); sql_exec($stmt, $params); }
function news_delete($id) { $sql = "DELETE FROM `news` WHERE `id` = " . $id; return sql_exec($sql); }
function photo_insert($data) { $sql = "INSERT INTO img\n\t\t\t(title, path)\n\t\t\tVALUES\n\t\t\t('" . $data['title'] . "', '" . $data['image'] . "')\t\t\n\t"; sql_exec($sql); }