Add the ?ENCODING? parameter to the "db copy" command. If used, it will translate from the given encoding to UTF-8

FossilOrigin-Name: ac27c2f81654f8d6ce8ef084c98b408c8e9e96dbfccc24a4c8d3d8d5190d932d
diff --git a/manifest b/manifest
index c14ffe8..9459c81 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Ensure\sthat\sextension\ssources\salso\sinherit\sthe\sdebugging-related\sflags\sfrom\s--debug\sor\s--dev.
-D 2025-03-31T10:54:09.382
+C Add\sthe\s?ENCODING?\sparameter\sto\sthe\s"db\scopy"\scommand.\sIf\sused,\sit\swill\stranslate\sfrom\sthe\sgiven\sencoding\sto\sUTF-8
+D 2025-03-31T11:24:10.202
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -794,7 +794,7 @@
 F src/sqliteLimit.h 6d817c28a8f19af95e6f4921933b7fbbca48a962bce0eb0ec81e8bb3ef38e68b
 F src/status.c 0e72e4f6be6ccfde2488eb63210297e75f569f3ce9920f6c3d77590ec6ce5ffd
 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
-F src/tclsqlite.c 767a11d470b031e85f51b8924a0e8929b2362ff1975aee3474a10eba3c2e0d36
+F src/tclsqlite.c b13fe776a38910f237b5b9861060c83eaa671533f341f49b5eff9a084468f78d
 F src/tclsqlite.h 65e2c761446e1c9fa0342b7d2612a703483643c8b6a316d12a65b745a4727395
 F src/test1.c e89a11192dd15da20e8f7dc0731297182b2fff56cf4afe6ca6f9aeab890595c5
 F src/test2.c 62f0830958f9075692c29c6de51b495ae8969e1bef85f239ffcd9ba5fb44a5ff
@@ -1725,7 +1725,7 @@
 F test/table.test 7862a00b58b5541511a26757ea9c5c7c3f8298766e98aa099deec703d9c0a8e0
 F test/tableapi.test e37c33e6be2276e3a96bb54b00eea7f321277115d10e5b30fdb52a112b432750
 F test/tableopts.test dba698ba97251017b7c80d738c198d39ab747930
-F test/tclsqlite.test ad0bbd92edabe64cc91d990a0748142fe5ab962d74ac71fa3bfa94d50d2f4c87
+F test/tclsqlite.test c627fd82e2028d9f03d3f2aafb25361daeb3fd09ea3f933db9114f63e320d7e7
 F test/tempdb.test 4cdaa23ddd8acb4d79cbb1b68ccdfd09b0537aaba909ca69a876157c2a2cbd08
 F test/tempdb2.test 353864e96fd3ae2f70773d0ffbf8b1fe48589b02c2ec05013b540879410c3440
 F test/tempfault.test 0c0d349c9a99bf5f374655742577f8712c647900
@@ -2216,8 +2216,11 @@
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P e48189ed33fa9d02b23c18255c7b4c6cab2a6d4b62f7c1edbb0a58ab329735fc
-R 900351079f392a3dac0ffc6765fe20f2
-U stephan
-Z 4c01788cf2ee043c6a538c02c303b015
+P 3e96b772a46638bc25e036de053d620ded3350871ee10e06fd6fe51429934b0d
+R 998b143fedcb6afb3f27ef334de6e12f
+T *branch * db-copy-encoding
+T *sym-db-copy-encoding *
+T -sym-trunk *
+U jan.nijtmans
+Z e388c1b3a45ffe93645e261095f25c2d
 # Remove this line to create a well-formed Fossil manifest.
diff --git a/manifest.uuid b/manifest.uuid
index 3e231d6..1798fbf 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-3e96b772a46638bc25e036de053d620ded3350871ee10e06fd6fe51429934b0d
+ac27c2f81654f8d6ce8ef084c98b408c8e9e96dbfccc24a4c8d3d8d5190d932d
diff --git a/src/tclsqlite.c b/src/tclsqlite.c
index 7675a91..31f64d1 100644
--- a/src/tclsqlite.c
+++ b/src/tclsqlite.c
@@ -2531,10 +2531,11 @@
     Tcl_Obj *pResult;           /* interp result */
 
     const char *zSep;
+    const char *zEnc = NULL;
     const char *zNull;
-    if( objc<5 || objc>7 ){
+    if( objc<5 || objc>8 ){
       Tcl_WrongNumArgs(interp, 2, objv,
-         "CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR?");
+         "CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR? ?ENCODING?");
       return TCL_ERROR;
     }
     if( objc>=6 ){
@@ -2547,6 +2548,9 @@
     }else{
       zNull = "";
     }
+    if( objc>=8 ){
+      zEnc = Tcl_GetStringFromObj(objv[7], 0);
+    }
     zConflict = Tcl_GetStringFromObj(objv[2], 0);
     zTable = Tcl_GetStringFromObj(objv[3], 0);
     zFile = Tcl_GetStringFromObj(objv[4], 0);
@@ -2612,6 +2616,10 @@
       return TCL_ERROR;
     }
     Tcl_SetChannelOption(NULL, in, "-translation", "auto");
+    if (zEnc && *zEnc && Tcl_SetChannelOption(interp, in, "-encoding", zEnc) != TCL_OK) {
+        sqlite3_finalize(pStmt);
+        return TCL_ERROR;
+    }
     azCol = malloc( sizeof(azCol[0])*(nCol+1) );
     if( azCol==0 ) {
       Tcl_AppendResult(interp, "Error: can't malloc()", (char*)0);
@@ -2624,9 +2632,12 @@
     zCommit = "COMMIT";
     while( Tcl_GetsObj(in, str)>=0 ) {
       char *z;
-      Tcl_Size byteLen;
       lineno++;
-      zLine = (char *)Tcl_GetByteArrayFromObj(str, &byteLen);
+      if (zEnc && *zEnc) {
+          zLine = Tcl_GetString(str);
+      }else {
+          zLine = (char *)Tcl_GetByteArrayFromObj(str, NULL);
+      }
       azCol[0] = zLine;
       for(i=0, z=zLine; *z; z++){
         if( *z==zSep[0] && strncmp(z, zSep, nSep)==0 ){
diff --git a/test/tclsqlite.test b/test/tclsqlite.test
index 0758abd..851130f 100644
--- a/test/tclsqlite.test
+++ b/test/tclsqlite.test
@@ -153,7 +153,7 @@
 do_test tcl-1.22 {
   set v [catch {db copy} msg]
   lappend v $msg
-} {1 {wrong # args: should be "db copy CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR?"}}
+} {1 {wrong # args: should be "db copy CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR? ?ENCODING?"}}
 do_test tcl-1.23 {
   set v [catch {sqlite3 db2 test.db -vfs nosuchvfs} msg]
   lappend v $msg