svenvc / p3 Goto Github PK
View Code? Open in Web Editor NEWA lean and mean PostgreSQL client for Pharo
License: MIT License
A lean and mean PostgreSQL client for Pharo
License: MIT License
Trying to select a _varchar (array) column I get this Error (cannot convert typeOid 1015):
P3Converter(Object)>>error:
[ self
error: 'P3 cannot convert typeOid ' , description typeOid asString ] in P3Converter>>convert:length:description:
IdentityDictionary(Dictionary)>>at:ifAbsent:
P3Converter>>convert:length:description:
P3RowFieldDescription>>convert:length:using:
P3Client>>processDataRowUsing:
[ :out |
[ self readMessage tag = $C ]
whileFalse: [ self assert: message tag = $D.
out nextPut: (self processDataRowUsing: result descriptions) ] ] in P3Client>>runQueryResult
Array class(SequenceableCollection class)>>new:streamContents:
Array class(SequenceableCollection class)>>streamContents:
P3Client>>runQueryResult
P3Client>>query:
[ client
query: 'select id,locale,created_at,confidential,rights from users limit 3' ] in [ :client |
[ client
query: 'select id,locale,created_at,confidential,rights from users limit 3' ]
ensure: [ client close ] ] in UndefinedObject>>DoIt
BlockClosure>>ensure:
[ :client |
[ client
query: 'select id,locale,created_at,confidential,rights from users limit 3' ]
ensure: [ client close ] ] in UndefinedObject>>DoIt
P3Client(Object)>>in:
UndefinedObject>>DoIt
OpalCompiler>>evaluate
RubSmalltalkEditor>>evaluate:andDo:
RubSmalltalkEditor>>highlightEvaluateAndDo:
[ textMorph textArea editor highlightEvaluateAndDo: ann action.
textMorph shoutStyler style: textMorph text ] in [ textMorph textArea
handleEdit: [ textMorph textArea editor highlightEvaluateAndDo: ann action.
textMorph shoutStyler style: textMorph text ] ] in GLMMorphicPharoScriptRenderer(GLMMorphicPharoCodeRenderer)>>actOnHighlightAndEvaluate:
RubEditingArea(RubAbstractTextArea)>>handleEdit:
[ textMorph textArea
handleEdit: [ textMorph textArea editor highlightEvaluateAndDo: ann action.
textMorph shoutStyler style: textMorph text ] ] in GLMMorphicPharoScriptRenderer(GLMMorphicPharoCodeRenderer)>>actOnHighlightAndEvaluate:
WorldState>>runStepMethodsIn:
WorldMorph>>runStepMethods
WorldState>>doOneCycleNowFor:
WorldState>>doOneCycleFor:
WorldMorph>>doOneCycle
WorldMorph class>>doOneCycle
[ [ WorldMorph doOneCycle.
Processor yield.
false ] whileFalse: [ ] ] in MorphicUIManager>>spawnNewProcess
[ self value.
Processor terminateActive ] in BlockClosure>>newProcess
Currently the P3PreparedStatement >> #bindString: method just sends asString to each parameter. This works for some objects like Strings, Integers and Booleans, but not for ByteArrays, ScaledDecimals and probably some others.
I think we need a more intelligent conversion strategy. I see two options:
writeAsP3TextParameterOn: aStream type: aParameterDescription
"default implementation"
self printOn: aStream
And for ByteArray:
writeAsP3TextParameterOn: aStream type: aParameterDescription
aStream nextPutAll: '\x'; nextPutAll: self hex
I think the seconds option is the most flexible but this option does require adding some class extensions.
Hi, I can not find standard class in Pharo for IPv4 and IPv6 addresses, so probably we can just use text representation for PostgreSQL type inet
and friends ?
If that is accepted, I could make a PR.
Hello, psql prepared statements are identified by "name" (https://www.postgresql.org/docs/current/view-pg-prepared-statements.html), but in P3 client, the whole query is used as name - but, psql prepared statement name is limited :(
Imagine this two queries:
select id, name, enabled from table1 where name = ''123'' and id = 1
This query is prepared - OK.
Second query:
select id, name, enabled from table1 where name = ''123'' and id = 2
Bang! PostgreSQL error message: P3Error PostgreSQL prepared statement "select id, name, enabled from table1 where name = '123' and id = 2" already exists
How to solve this? Add second peramater to the P3Client prepare: or maybe better, use some sort of hashes as prepared statement names internally?
Just a few minutes in to trying P3. After doing...
Metacello new
baseline: 'P3';
repository: 'github://svenvc/P3';
load.
Doing...
(P3Client new url: 'psql://postgres:xxxxx@localhost:5432/nyc_data') in: [ :client |
[ client isWorking ] ensure: [ client close ] ].
produces... "P3Error PostgreSQL Password required"
Tracing through, in P3CLient>>connect I find...
self ==> a P3Client(psql://postgres:xxxxxx@localhost:5432/nyc_data)
before sending #reset, and after...
self ==> a P3Client(psql://localhost:5432/)
Now it works if I comment out "self reset".
I have the following custom column type: CREATE TYPE public.money_with_currency AS (currency_code char(3), amount numeric(20,8))
When running: select * from table
with that column, I'm getting: P3Error Cannot convert type with OID 23409
Do you have any suggestions on how I could pass that type to P3?
... for new/prospective contributors?
Hi Sven,
I've managed to run our builds using GitHub actions and running the test suite against several PostgreSQL versions.
See for example:
https://github.com/ba-st/Sagan/actions/runs/161071269
If this kind of setup is of interest, I can provide a PR setting up the P3 builds to run against all the supported PostgreSQL versions.
When the database you try to connect does not exist, the method
P3MessageBuffer>>#readFrom:
(called from P3Client>>#readMessageOnError:
)
fails because the readStream next
returns nil
and the internal error handling does not expect such case.
Pharo 7 latest 32 bit, Ubuntu 16.04LTS, local postgres install
Following the glorp booklet, and adapting it to P3.
Metacello new
baseline: 'P3';
repository: 'github://svenvc/P3';
load: 'glorp'.
PharoDatabaseAccessor DefaultDriver: P3DatabaseDriver.
(section 4.5)
login := Login new
database: PostgreSQLPlatform new;
username: 'un';
password: 'pw';
connectString: 'localhost:5432_stephan';
encodingStrategy: #utf8;
yourself.
session := GlorpBookDescriptorSystem sessionForLogin: login.
session login
gives a
Instance of P3Client did not understand #queryEncoding
In the Unit tests section, you have the class name as P3ClientTests, whereas it should be P3ClientTest
The error handling in P3 uses general error:
calls on many places when something fails. It should signal custom errors with own classes so it can be more easily tested, converted and translated.
Hi,
I had to migrate from Pharo 8 to 9 and re-installed P3 with the following scripts (the same i had used to install P3 in Pharo 8)
Metacello new
baseline: 'P3';
repository: 'github://svenvc/P3';
load.
and
Metacello new
baseline: 'P3';
repository: 'github://svenvc/P3';
load: 'glorp'.
I also re-installed DBXTalk/Glorp/main
and "do-it" : PharoDatabaseAccessor DefaultDriver: P3DatabaseDriver.
Before that i installed Spec2.
Then i tried to run this script
(P3Client new url: 'psql://Richard:lulosa.2MA@localhost:5432/Glazux') in: [ :client |
[ client query: 'SELECT * FROM ingredients' ] ensure: [ client close ] ].
I probably forgot to do something but i don't remember what. Do i need to install a MetaRepoForPharo? But which version?
Thanks for help
Richard
(btw: the same script runs ok in Pharo 8)
server : postgresql 10.6 with gentoo linux
pharo : pharo 7.0
test code :
(P3Client new url: 'psql://frontend:[email protected]:5432/pegarelease') in: [ :client |
[ client query: 'SELECT * FROM system_countries' ] ensure: [ client close ] ].
but encounterd this error...
readTimezoneWithId : [ ^ self error: 'Unknown Timezone ID: ' , id asString ]
id Value is "ROK". how to solve this?
I just tested P3 with Pharo 7 and I got the following error message : Instance of ZnCharacterReadStream did not understand #binary.
The error is fired in ZTimezone >> fromFile: file
Using glorp, I am trying to specify platform serial
or platform bigint
and realising that neither exists. The serial type in my experience seems pretty standard for primary key use. Would it be hard to add support for these? I understand that array support may be a bit more involved but is also rather more rare in use than serial types.
I'm attempting to use pgcrypto, specifically this: select crypt('password', gen_salt('bf'))
and I'm unable to make it work. I've tried with prepared statements and formatted statements alike trying to replace 'bf' with a parameter $2 and trying to just leave it inline with the single quotes escaped like so: gen_salt(''bf'')
. I thought this would be straightforward but I'm a bit stumped.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.