Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Patches

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 06:26 AM
Merlin Moncure
 
Posts: n/a
Default libpq type system 0.9a

Yesterday, we notified -hackers of the latest version of the libpq
type system. Just to be sure the right people are getting notified,
we are posting the latest patch here as well. Would love to get some
feedback on this.

The latest version of libpq type system is available here:
http://www.esilo.com/projects/postgr...ys-0.9a.tar.gz

The following modifications where made:
*) documentation fixes
*) parameter resets are no longer automatic
*) updated to patch vs. REL8_3_STABLE

Merlin Moncure & Andrew Chernow
eSilo

--
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://mail.postgresql.org/mj/mj_www...=pgsql-patches

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 06:26 AM
Florian G. Pflug
 
Posts: n/a
Default Re: libpq type system 0.9a

Merlin Moncure wrote:
> Yesterday, we notified -hackers of the latest version of the libpq
> type system. Just to be sure the right people are getting notified,
> we are posting the latest patch here as well. Would love to get some
> feedback on this.

Sorry if this has been discussed before, but why is it necessary
to specify the type when calling PQgetf on a result? It seems that this
formatting string *always* has to match the type list of your select
statement, no?

regards, Florian Pflug


--
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://mail.postgresql.org/mj/mj_www...=pgsql-patches

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 06:26 AM
Merlin Moncure
 
Posts: n/a
Default Re: libpq type system 0.9a

On Wed, Mar 5, 2008 at 5:47 PM, Florian G. Pflug <fgp@phlo.org> wrote:
> Merlin Moncure wrote:
> > Yesterday, we notified -hackers of the latest version of the libpq
> > type system. Just to be sure the right people are getting notified,
> > we are posting the latest patch here as well. Would love to get some
> > feedback on this.

> Sorry if this has been discussed before, but why is it necessary
> to specify the type when calling PQgetf on a result? It seems that this
> formatting string *always* has to match the type list of your select
> statement, no?


yes...it always has to match. the format string requirements could in
theory be relaxed (for 'get') but this would break symmetry with 'put'
and you would lose a sanity check...getf like scanf writes directly
into application memory so the double-specifying (directly in the
format string and indirectly in the query) isn't necessarily a bad
thing. imagine if your application was 'select * from table' and one
of the field types changed...disaster.

merlin

--
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://mail.postgresql.org/mj/mj_www...=pgsql-patches

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 06:26 AM
Andrew Chernow
 
Posts: n/a
Default Re: libpq type system 0.9a

Merlin Moncure wrote:
> On Wed, Mar 5, 2008 at 5:47 PM, Florian G. Pflug <fgp@phlo.org> wrote:
>> Merlin Moncure wrote:
>> > Yesterday, we notified -hackers of the latest version of the libpq
>> > type system. Just to be sure the right people are getting notified,
>> > we are posting the latest patch here as well. Would love to get some
>> > feedback on this.

>> Sorry if this has been discussed before, but why is it necessary
>> to specify the type when calling PQgetf on a result? It seems that this
>> formatting string *always* has to match the type list of your select
>> statement, no?

>
> yes...it always has to match. the format string requirements could in
> theory be relaxed (for 'get') but this would break symmetry with 'put'
> and you would lose a sanity check...getf like scanf writes directly
> into application memory so the double-specifying (directly in the
> format string and indirectly in the query) isn't necessarily a bad
> thing. imagine if your application was 'select * from table' and one
> of the field types changed...disaster.
>
> merlin
>
>


A few other reasons....

>>why is it necessary to specify the type when calling PQgetf on a result


Unlike PQgetvalue, all values returned by PQgetf are either native C types or
structures ... not C strings. When you call getf you must tell it what types to
read out of the result object. Like scanf, they must be the correctly sized
data types.

PGdate date;
int i4;
PQgetf(result, tup_num, "%date %int4", 0, &date, 1, &i4);

Specifying anything other than a %date or %int4 in the above example is a
programming error. You would be asking to fetch a value of the wrong type.
Without the formatting string, libpq would have to va_arg(ASSUME_T) your value.

// no specifier
int i;
PQgetf(result, tup, field, &i);

In the above, libpq would have to use PQftype to determine what the native C
type is of your variable argument. If PQftype returned INT8OID, you begin to
clobber your application's memory space ... va_arg(ap, long long) on a 32-bit
value. This problem is solved by telling libpq what data type you want from a
field.

Also, the libpq type system enforces strict type checking when performing getf
calls. This protects from mis-matches "programming errors" on types:

For example:

-- create table t (a int8);
PQresult *result = PQexec(conn, "SELECT a FROM t");
char *val = PQgetvalue(result, ...);
int a = atoi(val); // assumed its an int4

In the above example, the libpq user thinks the 'a' column of the 't' table is
an int4 when in fact its an int8. The above may work most of the time but will
eventually truncate the value and nip you in the butt. With PQgetf, you would
get an error saying the server returned an int8 and you are asking for an int4.
Thus, the programming bug would be squashed immediately.

Also, user-defined types are not known to libpq so PQftype would not really
work. They could if the libpq type system referenced data types by OID, but
this is not portable to other servers. It is more portable to use the type
name. For example, a company with 15 postgresql servers that use the same
collection of company-specific user-defined data types. The type names would be
the same across the 15 servers but there is no guarentee the OIDs would be.

Composites and arrays caused a few issues as well.

We also tried to provide as much protection as possible ... in the spirit of the
backend.

--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/

--
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://mail.postgresql.org/mj/mj_www...=pgsql-patches

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-19-2008, 06:27 AM
Alvaro Herrera
 
Posts: n/a
Default Re: libpq type system 0.9a

Merlin Moncure escribió:

> The latest version of libpq type system is available here:
> http://www.esilo.com/projects/postgr...ys-0.9a.tar.gz


This patch is not in diff -c format ... please provide a diff -c patch,
and add the URL to the wiki patch queue:
http://wiki.postgresql.org/wiki/CommitFest:March

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

--
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-19-2008, 06:27 AM
Merlin Moncure
 
Posts: n/a
Default Re: libpq type system 0.9a

On Tue, Mar 25, 2008 at 4:21 PM, Alvaro Herrera
<alvherre@commandprompt.com> wrote:
> Merlin Moncure escribió:
> > The latest version of libpq type system is available here:
> > http://www.esilo.com/projects/postgr...ys-0.9a.tar.gz

>
> This patch is not in diff -c format ... please provide a diff -c patch,
> and add the URL to the wiki patch queue:
> http://wiki.postgresql.org/wiki/CommitFest:March


converted to context diff (0.9b):
http://www.esilo.com/projects/postgr...ys-0.9b.tar.gz

will have wiki set up soon...need to get an account over there.

merlin

--
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-19-2008, 06:27 AM
Alvaro Herrera
 
Posts: n/a
Default Re: libpq type system 0.9a

Merlin Moncure escribió:
> Yesterday, we notified -hackers of the latest version of the libpq
> type system. Just to be sure the right people are getting notified,
> we are posting the latest patch here as well. Would love to get some
> feedback on this.


I had a look at this patch some days ago, and the first question in my
mind was: why is it explicitely on libpq? Why not have it as a separate
library (say libpqtypes)? That way, applications not using it would not
need to link to it. Applications interested in using it would just need
to add another -l switch to their link line.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

--
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-19-2008, 06:27 AM
Joe Conway
 
Posts: n/a
Default Re: libpq type system 0.9a

Alvaro Herrera wrote:
> Merlin Moncure escribió:
>> Yesterday, we notified -hackers of the latest version of the libpq
>> type system. Just to be sure the right people are getting notified,
>> we are posting the latest patch here as well. Would love to get some
>> feedback on this.

>
> I had a look at this patch some days ago, and the first question in my
> mind was: why is it explicitely on libpq? Why not have it as a separate
> library (say libpqtypes)? That way, applications not using it would not
> need to link to it. Applications interested in using it would just need
> to add another -l switch to their link line.
>


+1

Joe


--
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-19-2008, 06:27 AM
Andrew Chernow
 
Posts: n/a
Default Re: libpq type system 0.9a

Joe Conway wrote:
> Alvaro Herrera wrote:
>> Merlin Moncure escribió:
>>> Yesterday, we notified -hackers of the latest version of the libpq
>>> type system. Just to be sure the right people are getting notified,
>>> we are posting the latest patch here as well. Would love to get some
>>> feedback on this.

>>
>> I had a look at this patch some days ago, and the first question in my
>> mind was: why is it explicitely on libpq? Why not have it as a separate
>> library (say libpqtypes)? That way, applications not using it would not
>> need to link to it. Applications interested in using it would just need
>> to add another -l switch to their link line.
>>

>
> +1
>
> Joe
>
>


What is gained by having a separate library? Our changes don't bloat the
library size so I'm curious what the benefits are to not linking with it? If
someone doesn't want to use, they don't have to. Similar to the backend, there
is stuff in there I personally don't use (like geo types), but I'm not sure that
justifies a link option -lgeotypes.

The changes we made are closely tied to libpq's functionality. Adding PQputf to
simplify the parameterized API, adding PQgetf to compliment PQgetvalue and added
the ability to register user-defined type handlers (used by putf and getf).
PQgetf makes extensive use of PGresult's internal API, especially for arrays and
composites. Breaking this into a separate library would require an external
library to access the private internals of libpq.

Personally, I am not really in favor of this idea because it breaks apart code
that is very related. Although, it is doable.

--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/

--
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-19-2008, 06:27 AM
Andrew Chernow
 
Posts: n/a
Default Re: libpq type system 0.9a

Andrew Chernow wrote:
> Joe Conway wrote:
>> Alvaro Herrera wrote:
>>> Merlin Moncure escribió:
>>>> Yesterday, we notified -hackers of the latest version of the libpq
>>>> type system. Just to be sure the right people are getting notified,
>>>> we are posting the latest patch here as well. Would love to get some
>>>> feedback on this.
>>>
>>> I had a look at this patch some days ago, and the first question in my
>>> mind was: why is it explicitely on libpq? Why not have it as a separate
>>> library (say libpqtypes)? That way, applications not using it would not
>>> need to link to it. Applications interested in using it would just need
>>> to add another -l switch to their link line.
>>>

>>
>> +1
>>
>> Joe
>>
>>

>
> What is gained by having a separate library? Our changes don't bloat
> the library size so I'm curious what the benefits are to not linking
> with it? If someone doesn't want to use, they don't have to. Similar
> to the backend, there is stuff in there I personally don't use (like geo
> types), but I'm not sure that justifies a link option -lgeotypes.
>
> The changes we made are closely tied to libpq's functionality. Adding
> PQputf to simplify the parameterized API, adding PQgetf to compliment
> PQgetvalue and added the ability to register user-defined type handlers
> (used by putf and getf). PQgetf makes extensive use of PGresult's
> internal API, especially for arrays and composites. Breaking this into
> a separate library would require an external library to access the
> private internals of libpq.
>
> Personally, I am not really in favor of this idea because it breaks
> apart code that is very related. Although, it is doable.
>


I poked around to see how this would work. There are some problems.

1. members were added to PGconn so connection-based type handler information can
be copied to PGparam and PGresult objects.

2. members were added to PGresult, referenced in #1. To properly getf values,
the connection-based type handler information must be available to PGresult.
Otherwise, PQgetf would require an additional argument, a PGconn, which may have
been closed already.

3. PQfinish calls pqClearTypeHandler to free type info assigned to the PGconn.

4. PQclear also calls pqClearTypeHandlers

It would also remove some of the simplicity. Creating a connection would no
longer initialized type info, which gets copied to PGparam and PGresult. Type
info includes a list of built-in handlers and backend config, like
integer_datetimes, server-version, etc... That means an additional function
must be called after PQconnectdb. But where would the type info be stored? It
wouldn't exist in PGconn anymore? Also, this would require double frees. You
have to free the result as well as the type info since they are no longer one
object. Same holds true for a pgconn.

There is something elegant about not requiring additional API calls to perform a
putf or getf. It'll just work if you want to use it. You can use PQgetf on a
result returned by PQexec and you can use PQputf, PQparamExec followed by
PQgetvalue.

--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/

--
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:14 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557