Compare commits

..

4 Commits

Author SHA1 Message Date
Clemens Schwaighofer
5a0b09a916 Add DB\IO get prepare cursor array entries 2023-01-05 17:26:26 +09:00
Clemens Schwaighofer
98c6033c75 mo to js script set exectueable 2023-01-05 15:31:35 +09:00
Clemens Schwaighofer
6dcebc9b67 mo to js shell script 2023-01-05 15:30:51 +09:00
Clemens Schwaighofer
c97520e186 Update flatpickr javascript lib 2023-01-05 15:14:08 +09:00
7 changed files with 413 additions and 20 deletions

169
4dev/bin/mo_to_js.sh Executable file
View File

@@ -0,0 +1,169 @@
#!/bin/bash
# read source mo files and writes target js files in object form
# check for ARG 1 is "mv"
# then move the files directly and don't do manual check (don't create temp files)
FILE_MOVE=0;
if [ "${1}" = "mv" ]; then
echo "*** Direct write ***";
FILE_MOVE=1;
fi;
target='';
BASE_FOLDER=$(dirname $(readlink -f $0))"/";
# Assume script is in 4dev/bin
base_folder="${BASE_FOLDER}../../www/";
po_folder='../4dev/locale/'
mo_folder='includes/locale/';
target_folder='';
template_file_stump='##SUFFIX##translate-##LANGUAGE##.TMP.js';
# for output file names
source_list=(iw);
language_list=(en ja);
# set target names
if [ "${target}" == '' ]; then
echo "*** Non smarty ***";
TEXTDOMAINDIR=${base_folder}${mo_folder}.
# default is admin
TEXTDOMAIN=admin;
fi;
js_folder="layout/${TEXTDOMAIN}/javascript/";
error=0;
# this checks if the TEXTDOMAIN target actually exists
if [ ! -d "${base_folder}${js_folder}" ]; then
echo "Cannot find target javascript folder ${base_folder}${js_folder}";
error=1;
else
target_folder="${base_folder}${js_folder}";
fi;
if [ ${error} -eq 1 ]; then
exit;
fi;
# locale gettext po to mo translator master
for file in $(ls -1 ${base_folder}../4dev/locale/*.po); do
file=$(basename $file .po);
echo "Translate language ${file}";
locale=$(echo "${file}" | cut -d "-" -f 1);
domain=$(echo "${file}" | cut -d "-" -f 2);
if [ ! -d "${base_folder}/includes/locale/${locale}/LC_MESSAGES/" ]; then
mkdir -p "${base_folder}/includes/locale/${locale}/LC_MESSAGES/";
fi;
msgfmt -o ${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo ${base_folder}${po_folder}${locale}-${domain}.po;
done;
rx_msgid_empty="^msgid \"\"";
rx_msgid="^msgid \"";
rx_msgstr="^msgstr \""
# quick copy string at the end
quick_copy='';
for language in ${language_list[*]}; do
# I don't know which one must be set, but I think at least LANGUAGE
case ${language} in
ja)
LANG=ja_JP.UTF-8;
ENCODING=UTF-8;
LANGUAGE=ja;
;;
en)
# was en_JP.UTF-8
LANG=en_US.UTF-8;
ENCODING=UTF-8;
LANGUAGE=en;
;;
esac;
# write only one for language and then symlink files
template_file=$(echo ${template_file_stump} | sed -e "s/##SUFFIX##//" | sed -e "s/##LANGUAGE##/${LANG}/");
original_file=$(echo ${template_file} | sed -e 's/\.TMP//g');
if [ "${FILE_MOVE}" -eq 0 ]; then
file=${target_folder}${template_file};
else
file=${target_folder}${original_file};
fi;
echo "===> Write translation file ${file}";
echo ". = normal, : = escape, x = skip";
# init line [aka don't touch this file]
echo "// AUTO FILL, changes will be overwritten" > $file;
echo "// source: ${suffix}, language: ${language}" >> $file;
echo "// Translation strings in the format" >> $file;
echo "// \"Original\":\"Translated\""$'\n' >> $file;
echo "var i18n = {" >> $file;
# translations stuff
# read the po file
pos=0; # do we add a , for the next line
cat "${base_folder}${po_folder}${language}-${TEXTDOMAIN}.po" |
while read str; do
# echo "S: ${str}";
# skip empty
if [[ "${str}" =~ ${rx_msgid_empty} ]]; then
# skip on empty
echo -n "x";
# msgid is left, msgstr is right
elif [[ "${str}" =~ ${rx_msgid} ]]; then
echo -n ".";
# open left side
# TODO: how to handle multi line strings: or don't use them
# extract from between ""
str_source=$(echo "${str}" | sed -e "s/^msgid \"//" | sed -e "s/\"$//");
# close right side, if not last add ,
if [ "${pos}" -eq 1 ]; then
echo -n "," >> $file;
fi;
# all " inside string need to be escaped
str_source=$(echo "${str_source}" | sed -e 's/"/\\"/g');
# fix with proper layout
echo -n "\"$str_source\":\"$(TEXTDOMAINDIR=${TEXTDOMAINDIR} LANGUAGE=${language} LANG=${LANG} gettext ${TEXTDOMAIN} "${str_source}")\"" >> $file;
pos=1;
elif [[ "${str}" =~ ${rx_msgstr} ]]; then
# open right side (ignore)
echo -n "";
else
# general ignore (anything between or comments)
echo -n "";
fi;
done;
echo "" >> $file;
echo "};" >> $file;
echo " [DONE]";
# on no move
if [ "${FILE_MOVE}" -eq 0 ]; then
echo "===> Confirm all changes in ${file} and then move data to original";
echo "";
quick_copy=${quick_copy}"mv ${template_file} ${original_file}"$'\n';
fi;
# symlink to master file
for suffix in ${source_list[*]}; do
# symlink with full lang name
symlink_file[0]=$(echo ${template_file_stump} | sed -e "s/##SUFFIX##/${suffix}_/" | sed -e "s/##LANGUAGE##/${LANG}/" | sed -e 's/\.TMP//g');
# create second one with lang (no country) + encoding
symlink_file[1]=$(echo ${template_file_stump} | sed -e "s/##SUFFIX##/${suffix}_/" | sed -e "s/##LANGUAGE##/${LANGUAGE}\.${ENCODING}/" | sed -e 's/\.TMP//g');
for template_file in ${symlink_file[@]}; do
# if this is not symlink, create them
if [ ! -h "${template_file}" ]; then
echo "Create symlink: ${template_file}";
# symlik to original
cd "${target_folder}";
ln -sf "${original_file}" "${template_file}";
cd - >/dev/null;
fi;
done;
done;
done;
if [ "${FILE_MOVE}" -eq 0 ]; then
echo "";
echo "-- IN FOLDER: ${target_folder}";
echo "-- START: copy lines below to copy created over original --";
echo "${quick_copy}";
echo "-- END ----------------------------------------------------";
fi;
# __END__

View File

@@ -2770,7 +2770,7 @@ final class CoreLibsDBIOTest extends TestCase
}
// - prepared query execute
// dbPrepare, dbExecute, dbFetchArray
// dbPrepare, dbExecute, dbFetchArray, dbGetPrepareCursorValue
/**
* Undocumented function
@@ -2795,6 +2795,7 @@ final class CoreLibsDBIOTest extends TestCase
// 11: read query (if insert/update)
// 11: execute data to check (array)
// 12: insert data
// 13: prepated cursor array data match values
return [
// insert
'prepare query insert' => [
@@ -2818,6 +2819,14 @@ final class CoreLibsDBIOTest extends TestCase
],
// insert data (for select)
'',
// get prepared data
[
'pk_name' => 'table_with_primary_key_id',
'count' => 2,
'query' => 'INSERT INTO table_with_primary_key (row_int, uid) '
. 'VALUES ($1, $2) RETURNING table_with_primary_key_id',
'returning_id' => true,
],
],
// update
'prepare query update' => [
@@ -2844,6 +2853,14 @@ final class CoreLibsDBIOTest extends TestCase
//
"INSERT INTO table_with_primary_key (row_int, uid) VALUES "
. "(111, 'TEST A')",
//
[
'pk_name' => '',
'count' => 3,
'query' => 'UPDATE table_with_primary_key SET row_int = $1, '
. 'row_varchar = $2 WHERE uid = $3',
'returning_id' => false,
],
],
// select
'prepare select query' => [
@@ -2865,7 +2882,14 @@ final class CoreLibsDBIOTest extends TestCase
],
],
//
$insert_query
$insert_query,
//
[
'pk_name' => '',
'count' => 1,
'query' => 'SELECT row_int, uid FROM table_with_primary_key WHERE uid = $1',
'returning_id' => false,
],
],
// any query but with no parameters
'prepare select query no parameter' => [
@@ -2890,7 +2914,14 @@ final class CoreLibsDBIOTest extends TestCase
],
],
//
$insert_query
$insert_query,
//
[
'pk_name' => '',
'count' => 0,
'query' => 'SELECT row_int, uid FROM table_with_primary_key',
'returning_id' => false,
],
],
// no statement name (25)
'empty statement' => [
@@ -2907,6 +2938,13 @@ final class CoreLibsDBIOTest extends TestCase
[],
//
'',
//
[
'pk_name' => '',
'count' => 0,
'query' => '',
'returning_id' => false,
],
],
// no query (prepare 11)
// no prepared cursor found with statement name (execute 24)
@@ -2924,6 +2962,13 @@ final class CoreLibsDBIOTest extends TestCase
[],
//
'',
//
[
'pk_name' => '',
'count' => 0,
'query' => '',
'returning_id' => false,
],
],
// no db connection (prepare/execute 16)
// TODO no db connection test
@@ -2944,8 +2989,15 @@ final class CoreLibsDBIOTest extends TestCase
// no query but data for data only compare
'',
[],
//,
$insert_query
//
$insert_query,
//
[
'pk_name' => '',
'count' => 0,
'query' => 'SELECT row_int, uid FROM table_with_primary_key',
'returning_id' => false,
],
],
// insert wrong data count compared to needed (execute 23)
'wrong parmeter count' => [
@@ -2962,7 +3014,15 @@ final class CoreLibsDBIOTest extends TestCase
'',
[],
//
''
'',
//
[
'pk_name' => 'table_with_primary_key_id',
'count' => 2,
'query' => 'INSERT INTO table_with_primary_key (row_int, uid) VALUES '
. '($1, $2) RETURNING table_with_primary_key_id',
'returning_id' => true,
],
],
// execute does not return a result (22)
// TODO execute does not return a result
@@ -2975,6 +3035,7 @@ final class CoreLibsDBIOTest extends TestCase
* @covers ::dbPrepare
* @covers ::dbExecute
* @covers ::dbFetchArray
* @covers ::dbGetPrepareCursorValue
* @dataProvider preparedProvider
* @testdox prepared query $stm_name with $expected_prepare (warning $warning_prepare/error $error_prepare) and $expected_execute (warning $warning_execute/error $error_execute) [$_dataName]
*
@@ -2991,6 +3052,7 @@ final class CoreLibsDBIOTest extends TestCase
* @param string $expected_data_query
* @param array $expected_data
* @param string $insert_data
* @param array $prepare_cursor
* @return void
*/
public function testDbPrepared(
@@ -3006,7 +3068,8 @@ final class CoreLibsDBIOTest extends TestCase
string $error_execute,
string $expected_data_query,
array $expected_data,
string $insert_data
string $insert_data,
array $prepare_cursor,
): void {
// self::$log->setLogLevelAll('debug', true);
// self::$log->setLogLevelAll('print', true);
@@ -3116,6 +3179,15 @@ final class CoreLibsDBIOTest extends TestCase
);
}
// check dbGetPrepareCursorValue
foreach (['pk_name', 'count', 'query', 'returning_id'] as $key) {
$this->assertEquals(
$prepare_cursor[$key],
$db->dbGetPrepareCursorValue($stm_name, $key),
'Prepared cursor: ' . $key . ': failed assertion'
);
}
// reset all data
$db->dbExec("TRUNCATE table_with_primary_key");
$db->dbExec("TRUNCATE table_without_primary_key");
@@ -3123,6 +3195,90 @@ final class CoreLibsDBIOTest extends TestCase
$db->dbClose();
}
// dedicated error checks for prepare cursor return
/**
* Undocumented function
*
* @return array
*/
public function preparedProviderValue(): array
{
// 1: query (can be empty for do not set)
// 2: stm name
// 3: key
// 4: expected error return
return [
'no error' => [
"SELECT row_int, uid FROM table_with_primary_key",
'read',
'pk_name',
''
],
'statement name empty' => [
'',
'',
'',
'101',
],
'key empty' => [
'',
'read',
'',
'102',
],
'key invalid' => [
'',
'read',
'invalid',
'102',
],
'statement name not found' => [
'',
'invalid',
'pk_name',
'103',
],
];
}
/**
* test return prepare cursor errors
*
* @covers ::dbGetPrepareCursorValue
* @dataProvider preparedProviderValue
* @testdox prepared query $stm_name with $key expect error id $error_id [$_dataName]
*
* @param string $query
* @param string $stm_name
* @param string $key
* @param string $error_id
* @return void
*/
public function testDbGetPrepareCursorValue(
string $query,
string $stm_name,
string $key,
$error_id
): void {
$db = new \CoreLibs\DB\IO(
self::$db_config['valid'],
self::$log
);
if (!empty($query)) {
$db->dbPrepare($stm_name, $query);
$db->dbExecute($stm_name);
}
$db->dbGetPrepareCursorValue($stm_name, $key);
// match check error
$last_error = $db->dbGetLastError();
$this->assertEquals(
$error_id,
$last_error,
'get prepare cursor value error check'
);
}
// - schema set/get tests
// dbGetSchema, dbSetSchema

View File

@@ -145,6 +145,11 @@ print "PREPARE INSERT[ins_test_foo] STATUS: " . Support::printToString($status)
print "PREPARE INSERT PREVIOUS INSERTED: "
. print_r($db->dbReturnRow("SELECT test_foo_id, test FROM test_foo "
. "WHERE test_foo_id = " . $db->dbGetInsertPK()), true) . "<br>";
print "PREPARE CURSOR RETURN:<br>";
foreach (['pk_name', 'count', 'query', 'returning_id'] as $key) {
print "KEY: " . $key . ': ' . $db->dbGetPrepareCursorValue('ins_test_foo', $key) . "<br>";
}
// returning test with multiple entries
// $status = $db->db_exec(
// "INSERT INTO test_foo (test) VALUES "

View File

@@ -1,13 +1,13 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.ja = {}));
}(this, function (exports) { 'use strict';
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ja = {}));
}(this, (function (exports) { 'use strict';
var fp = typeof window !== "undefined" && window.flatpickr !== undefined
? window.flatpickr
: {
l10ns: {}
l10ns: {},
};
var Japanese = {
weekdays: {
@@ -20,7 +20,7 @@
"木曜日",
"金曜日",
"土曜日",
]
],
},
months: {
shorthand: [
@@ -50,11 +50,15 @@
"10月",
"11月",
"12月",
]
],
},
time_24hr: true,
rangeSeparator: " から ",
firstDayOfWeek: 1
monthAriaLabel: "月",
amPM: ["午前", "午後"],
yearAriaLabel: "年",
hourAriaLabel: "時間",
minuteAriaLabel: "分",
};
fp.l10ns.ja = Japanese;
var ja = fp.l10ns;
@@ -64,4 +68,4 @@
Object.defineProperty(exports, '__esModule', { value: true });
}));
})));

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -452,6 +452,11 @@ class IO
'71' => 'Failed to set search path/schema',
'80' => 'Trying to set an empty encoding',
'81' => 'Failed to set client encoding',
// for prepared cursor return
'101' => 'Statement name empty for get prepare cursor',
'102' => 'Key empty for get prepare cursir',
'103' => 'No prepared cursor with this name',
'104' => 'No Key with this name in the prepared cursor array'
];
// load the core DB functions wrapper class
@@ -3066,6 +3071,60 @@ class IO
return $this->field_names;
}
/**
* Returns the value for given key in statement
* Will write error if statemen id does not exist
* or key is invalid
*
* @param string $stm_name The name of the stored statement
* @param string $key Key field name in prepared cursor array
* Allowed are: pk_name, count, query, returning_id
* @return null|string|int|bool Entry from each of the valid keys
* Will return false on error
* Not ethat returnin_id also can return false
* but will not set an error entry
*/
public function dbGetPrepareCursorValue(string $stm_name, string $key)
{
// if no statement name
if (empty($stm_name)) {
$this->__dbError(
101,
false,
'No statement name given'
);
return false;
}
// if not a valid key
if (!in_array($key, ['pk_name', 'count', 'query', 'returning_id'])) {
$this->__dbError(
102,
false,
'Invalid key name'
);
return false;
}
// statement name not in prepared list
if (empty($this->prepare_cursor[$stm_name])) {
$this->__dbError(
103,
false,
'Statement name does not exist in prepare cursor array'
);
return false;
}
// key doest not exists, this will never hit as we filter out invalid ones
if (!isset($this->prepare_cursor[$stm_name][$key])) {
$this->__dbError(
104,
false,
'Key does not exist in prepare cursor array'
);
return false;
}
return $this->prepare_cursor[$stm_name][$key];
}
// ***************************
// ERROR AND WARNING DATA
// ***************************