Revision: 2159 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=2159&view=re... Author: frlan Date: 2011-08-20 15:05:19 +0000 (Sat, 20 Aug 2011)
Log Message: ----------- Tableconvert: Added a function to convert to SQL e.g. for preparing an INSERT-statement.
Modified Paths: -------------- trunk/geany-plugins/tableconvert/ChangeLog trunk/geany-plugins/tableconvert/README trunk/geany-plugins/tableconvert/src/tableconvert.c
Modified: trunk/geany-plugins/tableconvert/ChangeLog =================================================================== --- trunk/geany-plugins/tableconvert/ChangeLog 2011-08-16 09:28:51 UTC (rev 2158) +++ trunk/geany-plugins/tableconvert/ChangeLog 2011-08-20 15:05:19 UTC (rev 2159) @@ -1,3 +1,14 @@ +2011-08-19 Frank Lanitz frlan@frank.uvena.de + + * Added a function to convert to SQL e.g. for preparing an + INSERT-statement. + + +2011-08-15 Frank Lanitz frlan@frank.uvena.de + + * Move filetype specific functions into seperate functions. + + 2011-03-19 Frank Lanitz frlan@frank.uvena.de
* Make plugin function available via tools menu.
Modified: trunk/geany-plugins/tableconvert/README =================================================================== --- trunk/geany-plugins/tableconvert/README 2011-08-16 09:28:51 UTC (rev 2158) +++ trunk/geany-plugins/tableconvert/README 2011-08-20 15:05:19 UTC (rev 2159) @@ -31,7 +31,10 @@ push your keybinding. All line endings will be taken as end of a row and therefor transformed to fitting row endings.
-Currently the plugin is supporting HTML and LaTeX. +Currently the plugin is supporting +* HTML +* LaTeX +* SQL
HTML @@ -56,6 +59,26 @@ some weird output you didn't expect -- just don't try it if you have heart issues or working on an important document :)
+SQL +^^^ + +At SQL line endings will be replaced with with closing braces ) +followed by a komma if is not the last line. + +Tabulators will be repace with ', ', so in the end, a tabulator +seperated liste as e.g. + +foo baa +baa foo + +will be transformed to + +( + ('foo', 'baa'), + ('baa', 'foo') +) + + Development -----------
Modified: trunk/geany-plugins/tableconvert/src/tableconvert.c =================================================================== --- trunk/geany-plugins/tableconvert/src/tableconvert.c 2011-08-16 09:28:51 UTC (rev 2158) +++ trunk/geany-plugins/tableconvert/src/tableconvert.c 2011-08-20 15:05:19 UTC (rev 2159) @@ -141,6 +141,48 @@ return replacement_str; }
+static GString* convert_to_table_sql(gchar** rows) +{ + guint i; + guint j; + GString *replacement_str = NULL; + + /* Adding start */ + replacement_str = g_string_new("(\n"); + + /* Iteration onto rows and building up lines for replacement */ + for (i = 0; rows[i] != NULL ; i++) + { + gchar **columns = NULL; + + g_string_append(replacement_str, "\t('"); + columns = g_strsplit_set(rows[i], "\t", -1); + + for (j = 0; columns[j] != NULL; j++) + { + if (j > 0) + { + g_string_append(replacement_str, "','"); + } + g_string_append(replacement_str, columns[j]); + } + + if (rows[i+1] != NULL) + { + g_string_append(replacement_str, "'),\n"); + } + else + { + g_string_append(replacement_str, "')\n"); + } + + g_free(columns); + } + /* Adding the end of table */ + g_string_append(replacement_str, ")\n"); + return replacement_str; +} + void convert_to_table(gboolean header) { GeanyDocument *doc = NULL; @@ -182,6 +224,11 @@ replacement_str = convert_to_table_latex(rows, header); break; } + case GEANY_FILETYPES_SQL: + { + replacement_str = convert_to_table_sql(rows); + break; + } default: { replacement_str = NULL;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
plugins-commits@lists.geany.org