Difference between revisions of "Query Truxton"

From truxwiki.com
Jump to navigation Jump to search
(Created page with "Here's an example of how to query the Truxton database using Python. =Number of File Types= This will tell you how many types of files Truxton knows about. <source lang="pyt...")
 
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
Here's an example of how to query the Truxton database using Python.
 
Here's an example of how to query the Truxton database using Python.
 +
 +
To install the PostgreSQL library for Python:
 +
<pre>pip install "psycopg[binary,pool]"</pre>
  
 
=Number of File Types=
 
=Number of File Types=
Line 8: Line 11:
 
sys.path.append('C:/Program Files/Truxton/SDK')
 
sys.path.append('C:/Program Files/Truxton/SDK')
 
import truxton
 
import truxton
import psycopg2
+
import psycopg
import psycopg2.extras
 
  
def main():
+
def main() -> None:
 
   t = truxton.create()
 
   t = truxton.create()
  
   connection = psycopg2.connect(t.connectionstring)
+
   connection = psycopg.connect(t.connectionstring)
   database_cursor = connection.cursor(cursor_factory=psycopg2.extras.DictCursor)
+
   database_cursor = connection.cursor()
 
   database_cursor.execute("SELECT * FROM \"FileType\";")
 
   database_cursor.execute("SELECT * FROM \"FileType\";")
 
   database_rows = database_cursor.fetchall()
 
   database_rows = database_cursor.fetchall()
  
 
   print( "There are " + str(len(database_rows)) + " file types in Truxton" )
 
   print( "There are " + str(len(database_rows)) + " file types in Truxton" )
   return
+
 
 +
  connection.commit()
 +
  connection.close()
 +
 
 +
   return None
  
 
if __name__ == "__main__":
 
if __name__ == "__main__":
   main()
+
   sys.exit(main())
 
 
 
</source>
 
</source>

Latest revision as of 16:54, 11 September 2024

Here's an example of how to query the Truxton database using Python.

To install the PostgreSQL library for Python:

pip install "psycopg[binary,pool]"

Number of File Types

This will tell you how many types of files Truxton knows about.

import sys
sys.path.append('C:/Program Files/Truxton/SDK')
import truxton
import psycopg

def main() -> None:
  t = truxton.create()

  connection = psycopg.connect(t.connectionstring)
  database_cursor = connection.cursor()
  database_cursor.execute("SELECT * FROM \"FileType\";")
  database_rows = database_cursor.fetchall()

  print( "There are " + str(len(database_rows)) + " file types in Truxton" )

  connection.commit()
  connection.close()

  return None

if __name__ == "__main__":
  sys.exit(main())