Fossil SCM

Added symbolic_name_to_rid() DB binding.

stephan 2014-11-29 09:38 trunk
Commit 8815b65e6c11c3dff4b5fab1115f413f321f48ce
1 file changed +37
+37
--- src/db.c
+++ src/db.c
@@ -706,10 +706,39 @@
706706
if( rc==0 ){
707707
sqlite3_result_int64(context, mtime);
708708
}
709709
}
710710
711
+void db_sym2rid_function(
712
+ sqlite3_context *context,
713
+ int argc,
714
+ sqlite3_value **argv
715
+){
716
+ char const * arg;
717
+ char const * type;
718
+ if(1 != argc && 2 != argc){
719
+ sqlite3_result_error(context, "Expecting one or two arguments", -1);
720
+ return;
721
+ }
722
+ arg = (const char*)sqlite3_value_text(argv[0]);
723
+ if(!arg){
724
+ sqlite3_result_error(context, "Expecting a STRING argument", -1);
725
+ }else{
726
+ int rid;
727
+ type = (2==argc) ? sqlite3_value_text(argv[1]) : 0;
728
+ if(!type) type = "ci";
729
+ rid = symbolic_name_to_rid( arg, type );
730
+ if(rid<0){
731
+ sqlite3_result_error(context, "Symbolic name is ambiguous.", -1);
732
+ }else if(0==rid){
733
+ sqlite3_result_null(context);
734
+ }else{
735
+ sqlite3_result_int64(context, rid);
736
+ }
737
+ }
738
+}
739
+
711740
712741
/*
713742
** Open a database file. Return a pointer to the new database
714743
** connection. An error results in process abort.
715744
*/
@@ -738,10 +767,18 @@
738767
sqlite3_create_function(
739768
db, "is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
740769
);
741770
sqlite3_create_function(
742771
db, "if_selected", 3, SQLITE_UTF8, 0, file_is_selected,0,0
772
+ );
773
+ sqlite3_create_function(
774
+ db, "symbolic_name_to_rid", 1, SQLITE_UTF8, 0, db_sym2rid_function,
775
+ 0, 0
776
+ );
777
+ sqlite3_create_function(
778
+ db, "symbolic_name_to_rid", 2, SQLITE_UTF8, 0, db_sym2rid_function,
779
+ 0, 0
743780
);
744781
if( g.fSqlTrace ) sqlite3_trace(db, db_sql_trace, 0);
745782
re_add_sql_func(db);
746783
foci_register(db);
747784
sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
748785
--- src/db.c
+++ src/db.c
@@ -706,10 +706,39 @@
706 if( rc==0 ){
707 sqlite3_result_int64(context, mtime);
708 }
709 }
710
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
711
712 /*
713 ** Open a database file. Return a pointer to the new database
714 ** connection. An error results in process abort.
715 */
@@ -738,10 +767,18 @@
738 sqlite3_create_function(
739 db, "is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
740 );
741 sqlite3_create_function(
742 db, "if_selected", 3, SQLITE_UTF8, 0, file_is_selected,0,0
 
 
 
 
 
 
 
 
743 );
744 if( g.fSqlTrace ) sqlite3_trace(db, db_sql_trace, 0);
745 re_add_sql_func(db);
746 foci_register(db);
747 sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
748
--- src/db.c
+++ src/db.c
@@ -706,10 +706,39 @@
706 if( rc==0 ){
707 sqlite3_result_int64(context, mtime);
708 }
709 }
710
711 void db_sym2rid_function(
712 sqlite3_context *context,
713 int argc,
714 sqlite3_value **argv
715 ){
716 char const * arg;
717 char const * type;
718 if(1 != argc && 2 != argc){
719 sqlite3_result_error(context, "Expecting one or two arguments", -1);
720 return;
721 }
722 arg = (const char*)sqlite3_value_text(argv[0]);
723 if(!arg){
724 sqlite3_result_error(context, "Expecting a STRING argument", -1);
725 }else{
726 int rid;
727 type = (2==argc) ? sqlite3_value_text(argv[1]) : 0;
728 if(!type) type = "ci";
729 rid = symbolic_name_to_rid( arg, type );
730 if(rid<0){
731 sqlite3_result_error(context, "Symbolic name is ambiguous.", -1);
732 }else if(0==rid){
733 sqlite3_result_null(context);
734 }else{
735 sqlite3_result_int64(context, rid);
736 }
737 }
738 }
739
740
741 /*
742 ** Open a database file. Return a pointer to the new database
743 ** connection. An error results in process abort.
744 */
@@ -738,10 +767,18 @@
767 sqlite3_create_function(
768 db, "is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
769 );
770 sqlite3_create_function(
771 db, "if_selected", 3, SQLITE_UTF8, 0, file_is_selected,0,0
772 );
773 sqlite3_create_function(
774 db, "symbolic_name_to_rid", 1, SQLITE_UTF8, 0, db_sym2rid_function,
775 0, 0
776 );
777 sqlite3_create_function(
778 db, "symbolic_name_to_rid", 2, SQLITE_UTF8, 0, db_sym2rid_function,
779 0, 0
780 );
781 if( g.fSqlTrace ) sqlite3_trace(db, db_sql_trace, 0);
782 re_add_sql_func(db);
783 foci_register(db);
784 sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
785

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button