[DBD::Pg] Switch from char to SV, per ideas from the coropg project.

dbdpg-commits-gENoVmVU/[email protected] Wed, 20 Nov 2013 22:58:36 -0500
Newsgroups gmane.comp.db.postgresql.dbdpg.cvs
Message-ID <[email protected]>
Committed by Greg Sabino Mullane <greg-O9fzpki4YnJWk0Htik3J/[email protected]>

Switch from char to SV, per ideas from the coropg project.

---
 Pg.xs    | 4 ++--
 dbdimp.c | 9 ++++++++-
 dbdimp.h | 2 +-
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/Pg.xs b/Pg.xs
index 071648d..7363530 100644
--- a/Pg.xs
+++ b/Pg.xs
@@ -638,7 +638,7 @@ lo_export(dbh, lobjId, filename)
 void
 pg_putline(dbh, buf)
 	SV * dbh
-	char * buf
+	SV * buf
 	CODE:
 		ST(0) = (pg_db_putline(dbh, buf)!=0) ? &PL_sv_no : &PL_sv_yes;
 
@@ -646,7 +646,7 @@ pg_putline(dbh, buf)
 void
 putline(dbh, buf)
 	SV * dbh
-	char * buf
+	SV * buf
 	CODE:
 		ST(0) = (pg_db_putline(dbh, buf)!=0) ? &PL_sv_no : &PL_sv_yes;
 
diff --git a/dbdimp.c b/dbdimp.c
index c08efb7..0c2b8fd 100644
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -3819,10 +3819,12 @@ void dbd_st_destroy (SV * sth, imp_sth_t * imp_sth)
 
 
 /* ================================================================== */
-int pg_db_putline (SV * dbh, const char * buffer)
+int pg_db_putline (SV * dbh, SV * svbuf)
 {
 	dTHX;
 	D_imp_dbh(dbh);
+	const char * buffer;
+	STRLEN len;
 	int copystatus;
 
 	if (TSTART_slow) TRC(DBILOGFP, "%sBegin pg_db_putline\n", THEADER_slow);
@@ -3831,6 +3833,11 @@ int pg_db_putline (SV * dbh, const char * buffer)
 	if (PGRES_COPY_IN != imp_dbh->copystate)
 		croak("pg_putline can only be called directly after issuing a COPY FROM command\n");
 
+	if (!svbuf || !SvOK(svbuf))
+		croak("pg_putline can only be called with a defined value\n");
+
+	buffer = SvPV(svbuf,len);
+
 	TRACE_PQPUTCOPYDATA;
 	copystatus = PQputCopyData(imp_dbh->conn, buffer, (int)strlen(buffer));
 	if (-1 == copystatus) {
diff --git a/dbdimp.h b/dbdimp.h
index 380890e..a9e8081 100644
--- a/dbdimp.h
+++ b/dbdimp.h
@@ -196,7 +196,7 @@ SV * pg_stringify_array(SV * input, const char * array_delim, int server_version
 
 int pg_quickexec (SV *dbh, const char *sql, const int asyncflag);
 
-int pg_db_putline (SV *dbh, const char *buffer);
+int pg_db_putline (SV *dbh, SV *svbuf);
 
 int pg_db_getline (SV *dbh, SV * svbuf, int length);
 
-- 
1.8.4