ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/PApp-SQL/SQL.xs
(Generate patch)

Comparing PApp-SQL/SQL.xs (file contents):
Revision 1.6 by root, Sun Apr 22 17:03:28 2001 UTC vs.
Revision 1.12 by root, Thu Apr 11 01:02:10 2002 UTC

6# define get_sv perl_get_sv 6# define get_sv perl_get_sv
7# define call_method perl_call_method 7# define call_method perl_call_method
8# define call_sv perl_call_sv 8# define call_sv perl_call_sv
9#endif 9#endif
10 10
11#if (PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION <= 5)) 11#if (PERL_VERSION > 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION >= 6))
12# define CAN_UTF8 1 12# define CAN_UTF8 1
13#endif 13#endif
14 14
15static SV * 15static SV *
16sql_upgrade_utf8 (SV *sv) 16sql_upgrade_utf8 (SV *sv)
79 79
80 dbh = SvRV (dbh); 80 dbh = SvRV (dbh);
81 81
82 lru_hash; 82 lru_hash;
83 83
84 /*fprintf (stderr, "F: %08lx %s\n", hash, SvPV_nolen (sql));/*D*/
85
86 n = &lru_list; 84 n = &lru_list;
87 do { 85 do {
88 n = n->next; 86 n = n->next;
89 if (!n->hash) 87 if (!n->hash)
90 return 0; 88 return 0;
112 n = lru_list.prev; 110 n = lru_list.prev;
113 111
114 lru_list.prev = n->prev; 112 lru_list.prev = n->prev;
115 n->prev->next = &lru_list; 113 n->prev->next = &lru_list;
116 114
117 /*fprintf (stderr, "N: %s\n", SvPV_nolen (n->sql));/*D*/
118
119 SvREFCNT_dec (n->dbh); 115 SvREFCNT_dec (n->dbh);
120 SvREFCNT_dec (n->sql); 116 SvREFCNT_dec (n->sql);
121 SvREFCNT_dec (n->sth); 117 SvREFCNT_dec (n->sth);
122 Safefree (n); 118 Safefree (n);
123 119
134 char *statement = SvPV (sql, len); 130 char *statement = SvPV (sql, len);
135 131
136 dbh = SvRV (dbh); 132 dbh = SvRV (dbh);
137 133
138 lru_hash; 134 lru_hash;
139
140 /*fprintf (stderr, "S: %08lx %s\n", hash, SvPV_nolen (sql));/*D*/
141 135
142 lru_size++; 136 lru_size++;
143 if (lru_size > lru_maxsize) 137 if (lru_size > lru_maxsize)
144 lru_nukeone (); 138 lru_nukeone ();
145 139
231 int count; 225 int count;
232 SV *dbh = ST(0); 226 SV *dbh = ST(0);
233 SV *sth; 227 SV *sth;
234 SV *sql; 228 SV *sql;
235 SV *execute; 229 SV *execute;
236 STRLEN dc; 230 STRLEN dc, dd; /* dummy */
237 231
238 /* save our arguments against destruction through function calls */ 232 /* save our arguments against destruction through function calls */
239 SP += items; 233 SP += items;
240 234
241 /* first check wether we should use an explicit db handle */ 235 /* first check wether we should use an explicit db handle */
242 if (!is_dbh (dbh)) 236 if (!is_dbh (dbh))
243 { 237 {
238 /* the next line doesn't work - check why later maybe */
244 dbh = get_sv ("DBH", FALSE); 239 /* dbh = get_sv ("DBH", FALSE);
245 if (!is_dbh (dbh)) 240 if (!is_dbh (dbh))
246 { 241 {*/
247 dbh = GvSV(DBH); 242 dbh = GvSV(DBH);
248 if (!is_dbh (dbh)) 243 if (!is_dbh (dbh))
244 croak ("sql_exec: no $DBH argument and no fallback in $PApp::SQL::DBH");
249 croak ("sql_exec: no $DBH found in current package or in PApp::SQL::"); 245 /*croak ("sql_exec: no $DBH found in current package or in PApp::SQL::");
250 } 246 }*/
251 } 247 }
252 else 248 else
253 arg++; /* we consumed one argument */ 249 arg++; /* we consumed one argument */
254 250
255 /* count the remaining references (for bind_columns) */ 251 /* count the remaining references (for bind_columns) */
272 { 268 {
273 SV *neu = sv_2mortal (newSVpv ("select count(*) > 0 from ", 0)); 269 SV *neu = sv_2mortal (newSVpv ("select count(*) > 0 from ", 0));
274 sv_catsv (neu, sql); 270 sv_catsv (neu, sql);
275 sv_catpv (neu, " limit 1"); 271 sv_catpv (neu, " limit 1");
276 sql = neu; 272 sql = neu;
277 ix -= 6; /* sql_fetch */ 273 ix -= 4; /* sql_fetch */
278 } 274 }
279 275
280 /* check cache for existing statement handle */ 276 /* check cache for existing statement handle */
281 sth = lru_fetch (dbh, sql); 277 sth = lru_fetch (dbh, sql);
282 if (!sth) 278 if (!sth)
290 SPAGAIN; 286 SPAGAIN;
291 287
292 if (count != 1) 288 if (count != 1)
293 croak ("sql_exec: unable to prepare() statement '%s': %s", 289 croak ("sql_exec: unable to prepare() statement '%s': %s",
294 SvPV (sql, dc), 290 SvPV (sql, dc),
295 SvPV (get_sv ("DBI::errstr", TRUE), dc)); 291 SvPV (get_sv ("DBI::errstr", TRUE), dd));
296 292
297 sth = POPs; 293 sth = POPs;
298 294
299 lru_store (dbh, sql, sth); 295 lru_store (dbh, sql, sth);
300 } 296 }
317 SPAGAIN; 313 SPAGAIN;
318 314
319 if (count != 1) 315 if (count != 1)
320 croak ("sql_exec: execute() didn't return any value ('%s'): %s", 316 croak ("sql_exec: execute() didn't return any value ('%s'): %s",
321 SvPV (sql, dc), 317 SvPV (sql, dc),
322 SvPV (get_sv ("DBI::errstr", TRUE), dc)); 318 SvPV (get_sv ("DBI::errstr", TRUE), dd));
323 319
324 execute = POPs; 320 execute = POPs;
325 321
326 if (!SvTRUE (execute)) 322 if (!SvTRUE (execute))
327 croak ("sql_exec: unable to execute statement '%s' (%s)", 323 croak ("sql_exec: unable to execute statement '%s' (%s)",
328 SvPV (sql, dc), 324 SvPV (sql, dc),
329 SvPV (get_sv ("DBI::errstr", TRUE), dc)); 325 SvPV (get_sv ("DBI::errstr", TRUE), dd));
330 326
331 sv_setsv (GvSV(sql_exec), execute); 327 sv_setsv (GvSV(sql_exec), execute);
332 328
333 if (bind_first != bind_last) 329 if (bind_first != bind_last)
334 { 330 {
345 SPAGAIN; 341 SPAGAIN;
346 342
347 if (count != 1) 343 if (count != 1)
348 croak ("sql_exec: bind_columns() didn't return any value ('%s'): %s", 344 croak ("sql_exec: bind_columns() didn't return any value ('%s'): %s",
349 SvPV (sql, dc), 345 SvPV (sql, dc),
350 SvPV (get_sv ("DBI::errstr", TRUE), dc)); 346 SvPV (get_sv ("DBI::errstr", TRUE), dd));
351 347
352 if (!SvOK (POPs)) 348 if (!SvOK (POPs))
353 croak ("sql_exec: bind_columns() didn't return a true ('%s'): %s", 349 croak ("sql_exec: bind_columns() didn't return a true ('%s'): %s",
354 SvPV (sql, dc), 350 SvPV (sql, dc),
355 SvPV (get_sv ("DBI::errstr", TRUE), dc)); 351 SvPV (get_sv ("DBI::errstr", TRUE), dd));
356 } 352 }
357 353
358 /* free our arguments from the stack */ 354 /* free our arguments from the stack */
359 SP -= items; 355 SP -= items;
360 356

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines