<div dir="ltr">Hi Arthur,<div><br></div><div>1. The method which you've used - db.get_connection().executescript() is specific for SQLite only. </div><div>You need to use the method db.execute() which works for all databases: <a href="http://doc.ponyorm.com/database.html#execute" target="_blank">http://doc.ponyorm.com/database.html#execute</a></div>
<div>Also you can use methods for dropping the database tables:</div><div><a href="http://doc.ponyorm.com/database.html#drop_table" target="_blank">http://doc.ponyorm.com/database.html#drop_table</a></div><div><a href="http://doc.ponyorm.com/database.html#drop_all_tables" target="_blank">http://doc.ponyorm.com/database.html#drop_all_tables</a></div>
<div><br></div><div>2. The official way to get all entity attributes is getting the _attrs_ attribute from the entity class:</div><div><br></div><div> MyEntity._attrs_</div><div><br></div><div>It returns the list of all the entity attributes. You can iterate over this list and examine the attribute properties. For example, this is how you can print all attribute names which are not collections (collection means one-to-many relationship attribute):</div>
<div><br></div><div> for attr in MyEntity._attrs_:</div><div> if not attr.is_collection:</div><div> print <a href="http://attr.name" target="_blank">attr.name</a></div><div><br></div><div>Below you can see a couple of functions for getting attributes:</div>
<div><div><br></div><div>def get_all_attrs(entity_cls):</div><div> return [ attr for attr in entity_cls._attrs_ ]</div><div><br></div><div>def get_attrs_with_columns(entity_cls):</div><div> return [ attr for attr in entity_cls._attrs_with_columns_ ]</div>
<div><br></div><div>def get_collection_attrs(entity_cls):</div><div> return [ attr for attr in entity_cls._attrs_ if attr.is_collection ]</div><div><br></div><div>def get_all_attr_names(entity_cls):</div><div> return [ <a href="http://attr.name">attr.name</a> for attr in entity_cls._attrs_ ]</div>
</div><div><br></div><div>Please let us know if you have further questions.</div><div><br></div><div>Regards,</div>
<div>Alexey</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jun 19, 2014 at 3:13 AM, Goldberg, Arthur P <span dir="ltr"><<a>arthur.p.goldberg@mssm.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">
Pony's nifty -- thanks.
<div><br>
</div>
<div>Some questions:</div>
<div><br>
</div>
<div>1. Direct SQL. Suppose I want to drop a table. I thought that this would work because executescript() appears in examples</div>
<div>
<blockquote type="cite">
<div> sql = "DROP TABLE IF EXISTS %s;" % tableName</div>
<div> db.get_connection().executescript(sql)</div>
</blockquote>
</div>
<div>
<div><br>
</div>
</div>
<div>2. Entity class fields. Suppose I have</div>
<div><br>
</div>
<div>
<blockquote type="cite">
<div>class Subject(db.Entity):</div>
<div> FamilyID = Optional(str)</div>
<div> IndivID = PrimaryKey(str)</div>
<div> PatID = Optional(str, default='0')</div>
<div> MatID = Optional(str, default='0')</div>
<div> Sex = Required(str)</div>
<div> Pheno = Required(int)</div>
<div> SampleSet = Required(str)</div>
<div> variants = Set(Variant)</div>
</blockquote>
<blockquote type="cite">className = 'Subject' </blockquote>
<blockquote type="cite">self.slqobj = globals()[ className ]</blockquote>
</div>
<div>
<blockquote type="cite">
<div># I can get all fields in Subject with</div>
<div>self.slqobj._attrs_</div>
</blockquote>
</div>
<div>
<div><br>
</div>
</div>
<div>but is there an official method?</div>
<div><br>
</div>
<div>Thanks</div>
<div>Arthur</div>
<div><br>
<div>
<div style="color:rgb(0,0,0);font-family:Helvetica;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">
<div style="color:rgb(0,0,0);font-family:Helvetica;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">
<div style="color:rgb(0,0,0);font-family:Helvetica;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">
<span style="border-collapse:separate;border-spacing:0px">
<div style="word-wrap:break-word">
<span style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
<div style="word-wrap:break-word">
<span style="text-align:-webkit-auto;text-indent:0px">
<div style="word-wrap:break-word">
<span style="text-align:-webkit-auto;text-indent:0px">
<div style="word-wrap:break-word">
<span style="text-align:-webkit-auto;text-indent:0px">
<div style="word-wrap:break-word">
<span style="text-align:-webkit-auto;text-indent:0px">
<div style="word-wrap:break-word">
<span style="text-align:-webkit-auto;text-indent:0px">
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
<div style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
---</div>
<div> </div>
<div>Arthur Goldberg
<div style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
Associate Professor of Psychiatry</div>
<div>Seaver Autism Center and Icahn Institute for Genomics & Multiscale Biology</div>
<div>Icahn School of Medicine at Mount Sinai</div>
<div style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
Seaver Center, Room ABE-33</div>
<div style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
<a href="tel:212-241-4229" target="_blank">212-241-4229</a><br>
<a>Arthur.Goldberg@mssm.edu</a></div>
</div>
</div>
<div>Follow us on Twitter <a href="https://twitter.com/IcahnInstitute" target="_blank">@IcahnInstitute</a></div>
<div style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
<br>
</div>
</div>
</div>
</span></div>
</span></div>
</span></div>
</span></div>
</span></div>
</span></div>
</span></div>
</div>
</div>
<br>
<br>
</div>
<br>
</div>
</div>
<br>_______________________________________________<br>
ponyorm-list mailing list<br>
<a>ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div><br></div>